BookmarkSubscribeRSS Feed
dhrumil_patel
Fluorite | Level 6

Hello,

I would like to create a long series of indicator variables based on a set of criteria. The code I am using looks like this:

data test;
     set sample;
     array ind[91];
     do i=1 to dim(ind);
     do test=1 to 10 by 0.1;
          ind = (tenure >= test and risk="low" and value="low");
     end;
     end;
run;

The basic idea is to create ind1 to ind99 based on whether tenure is greater than or equal to the test counter and whether the levels of risk and value are low. Running this, I seem to be getting 0s for the indicator variables created, even when the values for a particular record meet the criteria.

As a secondary matter, I would like to ideally generalize this because I two other value levels for risk (medium and high) and 4 other value levels for value. My approach now is to create other sets of array variables for the other combinations of risk and value. But I suspect there is a better way. Would a multidimensional array help here?

Thanks,

Dhrumil Patel

2 REPLIES 2
Reeza
Super User

Why do you need all these indicator variables?

At any rate, why loop through it all? Set the array default to  and only start setting to 1 when tenure=test for starters.

Second, you can use do loops to loop over character values.

do value="low", "medium", "high";

output;

end;

ballardw
Super User

As written your loop

do test=1 to 10 by 0.1;

          ind = (tenure >= test and risk="low" and value="low");     

end;

 

1) does not properly reference the array, to refernce an element of the array you want something like: ind[i] = (<code goes here>);

2) is only ever going to yield the result for test= 10

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1243 views
  • 0 likes
  • 3 in conversation