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:
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
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;
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
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.
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.