BookmarkSubscribeRSS Feed
psbbboyz
Calcite | Level 5

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

3 REPLIES 3
shivas
Pyrite | Level 9

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

Alpay
Fluorite | Level 6

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

psbbboyz
Calcite | Level 5

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 446 views
  • 0 likes
  • 3 in conversation