Example 9.1 Converting Variable Types from Character to Numeric and Vice Versa

Goal

Read the value of a character variable and write its value to a numeric variable, and vice versa.

Example Features

Featured StepDATA step
Featured Step Options and StatementsINPUT and PUT functions

Input Data Set

Data set PRELIM_RESULTS contains preliminary test results for five test takers. TESTDATE and TEST_VERSION are numeric variables. SCORE is a character variable.

                  PRELIM_RESULTS

                                           test_
      Obs     id     testdate    score    version
       1     3205       41509     9         40012
       2     3019       30109     20          103
       3     4310           .               20101
       4     4817           .     0             .
       5     4182    11032009     18          251

Resulting Data Set

Output 9.1 RECODED_RESULTS Data Set

 Example 9.1 RECODED_RESULTS test_ Obs id testdate score version 1 3205 04/15/2009 9 40012 ...

Get Combining and Modifying SAS® Data Sets: Examples Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.