@alexist wrote:
@Astounding
Ok. I have an excel sheet with a few hundred cereal types that SAS should be using to change the characters (i.e. steel cut oatmeal) to an 8 digit numeric code. Would I need to do "if cereal1fc='Steel-cut oatmeal' then do;" for every single cereal type?
Thanks.
If the list of numeric values is relatively stable, i.e. it doesn't change every time you use it, a common way to handle this is to use a custom informat (and an associated format to display the character value when needed).
Proc format library=work;
/* INVALUE says I am going to create an informat*/
/* the upcase tells SAS to use the upper case of the
character value before comparing to the list, so "a" or "A"
both will yield the numeric value 10001000
Since the name of the informat does not start with $
SAS expects to create numeric values from the given
characters. The "other" is what to do if a value
not on your list is encountered. In this case it provides
an invalid data error message you may seen before
*/
invalue Char2Num (upcase)
'A' = 10001000
'B' = 10001100
'CAN' = 99999999
other=_error_
;
run;
data example;
informat x char2num.;
input x;
datalines;
a
B
caN
dog
;
run;
if you have the list in a data set you could use that to make a format, write format code or do a table look up.
... View more