06-08-2012 03:24 AM
I am facing the problem here. I am using sas 9.2 and would like to build a dataset in the following way.
I have a table called rules which has variable Name, and its lower and upper bound based classifications
age 1 20 Child
age 20 40 Youth
age 40 100 Oldies
Now i want to run this on a base data, and create a separate group variable which will indicate whether they are children Youth or Oldies.
I am stuck at this for quite sometime now trying to use macros to generate the if conditions, but end up getting a this statement is not valid or out of order as error.
Thanks in advance for the help.
06-08-2012 04:16 AM
Is this what you want..
input lbound hbound desc $;
1 20 Child
20 40 Youth
40 100 Oldies
data fmt (keep=FMTNAME START END LABEL TYPE);
length FMTNAME $30. START END $256.;
FMTNAME = 'age' ;
START = lbound;
END = hbound;
LABEL = desc;
TYPE = 'N' ;
proc format cntlin=fmt lib=work; run;
06-08-2012 04:26 AM
Without seeing your code it is impossible to know why you get the above mentioned error.
An alternative way could be using user-defined formats to assign labels(Ages 0 or greater than 100 are not accounted for).
1 -< 20 = 'Child' /* [1,20) */
20 -< 40 = 'Youth' /* [20,40) */
40 - 100 = 'Oldies' /* [40,100] */;
Group = PUT(Age,age.);
put (Age Group) (=);
06-08-2012 06:41 AM
Thanks a lot guys
I didn't know of proc format previously, and this definitely seems to be a better option than the previous idea of mine