41
7
Other = 9999
;
run;
aertdnum = INPUT(STRIP(UPCASE(aertd)), $rtdfmt.);
***
A few useful options that the INVALUE statement has that the VALUE statement does not are the options JUST and
UPCASE.
If you rewrite the statement:
invalue rtdfmt as invalue rtdfmt (JUST UPCASE)
You can write the conversion statement as
aertdnum = INPUT(aertd, $rtdfmt.);
since the variable aertd is stripped and upcased by the options JUST and UPCASE.
CONVERTING A NUMERIC VARIABLE TO A CHARACTER VARIABLE USING PROC
FORMAT
Converting a numeric variable to a character variable is almost the same as converting a character variable to a new
character variable. The only exception is that the value name (lbcat below) doesn’t start with a $ (i.e. $lbcat)
and the unformatted values are not in quotes.
proc format;
value lbcat (DEFAULT =100)
1 = 'Chemistry: Metabolic Substrates'
2 = 'Chemistry: Hepatic Status Liver Function Tests'
3 = 'Chemistry: Renal Status Serum Metabolites'
4 = 'Chemistry: Serum Electrolytes'
5 = 'Chemistry: Other'
6 = 'Hematology: CBC'
7 = 'Hematology: Differential Counts'
8 = 'Hematology: Coagulation'
9 = 'Urinalysis: General'
10 = 'Urinalysis: Dipstick'
11 = 'Urinalysis: Microscopics'
12 = 'Urinalysis: Other'
;
run;
lbcatname = STRIP(PUT(lbcatnum, lbcat.);
***
Again, remember to include a format statement in your data step (i.e. format lbcatname $100.) and use the
DEFAULT option rather than trusting that SAS will create everything correctly for you.
***
You can also create a variable by checking for numeric ranges and output the result depending on which group the
data falls in. This can be useful when trying to group data in different groups so that you analyze.