DATA Step, Macro, Functions and more

Referring to multiple variables in if/then statement

Reply
Frequent Contributor
Posts: 138

Referring to multiple variables in if/then statement

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.

Super User
Posts: 19,822

Re: Referring to multiple variables in if/then statement

Posted in reply to Walternate

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.

Super User
Posts: 11,343

Re: Referring to multiple variables in if/then statement

Posted in reply to Walternate

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.

Ask a Question
Discussion stats
  • 2 replies
  • 203 views
  • 0 likes
  • 3 in conversation