BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zishaq
Obsidian | Level 7

Hi,

 

I'm looking to create a single data step where I use a repetitive IF statement for 24 columns (income_201001, income_201002, income_201003 ...... ,income_201012, income_201101,income_201102 ...... income_201112) . The first four numbers represent the year (i.e. take values 2010 or 2011) and the last two numbers represent months (1 to 12).

 

The IF statement I want to use is the following:

 

IF income_201001 > 0 then flag_1=1; ELSE flag_1=0;

IF income_201002 > 0 then flag_2=1; ELSE flag_2=0;

IF income_201111 > 0 then flag_23=1; ELSE flag_23=0;

IF income_201112 > 0 then flag_24=1; ELSE flag_24=0;

 

What's the quickest way to write this without having to repeat 24 lines of code?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

That is what the ARRAY statement is for.  Also boolean expressions evaluate as 0 or 1 already.

array income income_201001-income_201012 income_201101-income_201112 ;
array flag_ [24];
do index=1 to dim(income);
  flag_[index] = income[index] > 0;
end;

 

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

That is what the ARRAY statement is for.  Also boolean expressions evaluate as 0 or 1 already.

array income income_201001-income_201012 income_201101-income_201112 ;
array flag_ [24];
do index=1 to dim(income);
  flag_[index] = income[index] > 0;
end;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 921 views
  • 2 likes
  • 2 in conversation