BookmarkSubscribeRSS Feed
Walternate
Obsidian | Level 7

Hi everyone,

Basically, I have a large SAS assignment which I know how to do by hand, but I'm sure there are lots of useful shortcuts that I don't know about which could make it less cumbersome!

I have a Word document outlining about a thousand values that have been divided into 16 categories. I also have a SAS dataset in which each row can contain up to 10 variables containing the values that have been categorized in the Word document.

The only way I can think to do this is to code by hand:

If var1 in (abc, def, ghi, jkl) then category1=1;

else if var1 in (mno, pqr, stu, vwx) then category1=2;

...

else if var1 in (zzz, zyx, wvu, tsr) then category1=16;

if var2 in (abc, def, ghi, jkl) then category2=1;

else if var2 in (mno, pqr, stu, vwx) then category2=2;

etc.

As you can see, this gets very cumbersome very quickly, as I have 10 vars containing the values and 16 categories. Any shortcuts would be much appreciated!

Thanks.

2 REPLIES 2
Reeza
Super User

Proc format?

You'd have to provide more detailed examples for more detailed help. But generally, if its categorizing or recoding, look at a merge, hash or proc format instead of multiple if/then statements.

If you're doing the same thing across a whole bunch of variables consider an array as well.

ballardw
Super User

Depending on the structure and contents of your Word document you may be able to use it to make a dataset that will create formats.

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
  • 2 replies
  • 2090 views
  • 0 likes
  • 3 in conversation