BookmarkSubscribeRSS Feed
sas_it
Quartz | Level 8
I want the values jan, feb, mar, apr, may, jun, july, aur, sep, oct, nov, dec in a macro variable and using if condition i want to access each value and check. Eg. If month=jan then.. so i want to use macro variable. Is it possible to use arrays with macro variables. Pls help.
5 REPLIES 5
Cynthia_sas
SAS Super FREQ

Hi,
What code have you tried? When we teach the SAS Macro class, we recommend starting with a working program for one example where everything is hard-coded to make sure that you have working code. What will happen if month=jan or if month=feb -- will you have your macro program type an entire program or just type one line of code. Remember that the SAS Macro Facility only generates or types code for you. So the reason to start with a working program is so you know exactly what code has to be generated for each condition.

 
The short answer to your question is yes-- sort of -- you can create "numbered" values as SAS macro variables, such as &month1, &month2, &month3, etc and then you can test the values of those macro variables with a %IF statement. Or, you could create a long string and process through the string with a %DO loop without creating numbered macro variables. It depends on what you want to do.

However, you have to know what happens on the "true" condition and the "false" condition. Even though the macro variables can numbered and may look like array elements, they are not technically members of an array and you do not reference them as if you had issued an ARRAY statement for regular data set variables which were members of an array. And you can use a %DO loop in SAS macro code to reference either numbered macro variables or a long string of values in an orderly fashion. Here's one example using just a long string separated by spaces, then when one of the scanned values is equal to May, type some PROC PRINT code for processing:

Cynthia_sas_1-1621779835172.png

 

 



But it would be useful to see what code you've tried, to understand your data, to understand what your full task is and to know what the desired end result is.
Cynthia

sas_it
Quartz | Level 8
If month=jan then I want to calculate percentage at three levels ie school ,college and university.
Cynthia_sas
SAS Super FREQ
Hi:
The macro facility can type code procedure or data step code that calculates percentages, but the macro facility itself will not calculate percentages. As @Kurt_Bremser commented, you need to start with working code that calculates these percentages for one school for one month or however you need to have this accomplished. Then, THAT working code can be made dynamic by adding macro variables or macro programs.
Cynthia

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 5 replies
  • 788 views
  • 1 like
  • 3 in conversation