BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kurt_Bremser
Super User

something like

array nbimp2016 {*} nbimp201601-nbimp201606;
month_check = month(&date_risk);
if (nbimp2016{month_check} >= 3)
then HR_3 = 1;
else HR_3 = 0;

In the same vein, you could create a two-dimensional array with years and months.

Raitag
Fluorite | Level 6
 
Kurt_Bremser
Super User

@Raitag wrote:

Sorry i clicked on the wrong button

But by defining a two dimensional array i will have all my nbimpYYYYMM s value set to zero

won't i ?


A SAS array is just a "grid" that can be put upon existing variables to easily address them. It does not change values of variables per se.

If you define variables in the array that do not yet exist, then those are set to missing initially.

 

Edit:

and if you have lots of those nbimp variables, it will make sense to use macro programming to create the array definition.

Tom
Super User Tom
Super User

Your problem does not look like something that needs to use macro code. But your description of your data and the code you posted are at odds.  The code seems to be thinking there is a variable with the month in it,

PRODUCT|MONTH|VALUE
101|201606|25
101|201607|35

but the description seemed to say that the month is actually coded into the name of the variable.

PRODUCT|VAL201606|VAL201607
101|25|35

Which format is the data actually in?

Raitag
Fluorite | Level 6
the second format
the nbimpYYYYMM are variables that contains month in their name

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 19 replies
  • 2859 views
  • 0 likes
  • 7 in conversation