Dear All,
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
eg.
age 1 20 Child
age 20 40 Youth
age 40 100 Oldies
height.....
etc...
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.
CHeers
Sudharshan
Hi,
Is this what you want..
data rules;
input lbound hbound desc $;
cards;
1 20 Child
20 40 Youth
40 100 Oldies
;
run;
data fmt (keep=FMTNAME START END LABEL TYPE);
length FMTNAME $30. START END $256.;
set WORK.rules;
FMTNAME = 'age' ;
START = lbound;
END = hbound;
LABEL = desc;
TYPE = 'N' ;
run;
proc format cntlin=fmt lib=work; run;
data basetable;
input age;
desc=put(age,age.);
cards;
24
45
22
99
11
;
run;
Thanks,
Shiva
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).
Zafer
proc format;
value age
1 -< 20 = 'Child' /* [1,20) */
20 -< 40 = 'Youth' /* [20,40) */
40 - 100 = 'Oldies' /* [40,100] */;
run;
data test;
input Age;
Group = PUT(Age,age.);
put (Age Group) (=);
datalines;
1
19
20
39
40
100
;
run;
Age=1 Group=Child
Age=19 Group=Child
Age=20 Group=Youth
Age=39 Group=Youth
Age=40 Group=Oldies
Age=100 Group=Oldies
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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.