Is there something I need to do to use two macro variables in a row dynamically?
%let yearVar = 1617;
%let yearTypeVar = 'S';
This works:
data year&yearVar; set work.combined2;
run;
Using the second variable causes
data year&yearVar&yearTypeVar; set work.combined2;
run;
ERROR: User does not have appropriate authorization level for library WC000001.
data year&yearVar&yearTypeVar;
How does SAS know where the macro variable ends?
Make sure to end it with a period when using them in text or back to back.
data year&yearVar.&yearTypeVar.;
In general, using a period at the end always is going to lead to less errors than leaving it out.
PS. Yes, I know people on here will disagree with that last statement 🙂
Resolving the macro variables shows that your proposed data set name is illegal:
data year1617'S'; set work.combined2;
If you intended that your data set name should be:
year1617S
The usual way to achieve that would be to omit the quotes when assigning a value:
%let yearTypeVar = S;
Then in sections of the code where you need quotes, refer to the macro variable within double-quotes:
"&yearTypeVar"
data year&yearVar&yearTypeVar;
How does SAS know where the macro variable ends?
Make sure to end it with a period when using them in text or back to back.
data year&yearVar.&yearTypeVar.;
In general, using a period at the end always is going to lead to less errors than leaving it out.
PS. Yes, I know people on here will disagree with that last statement 🙂
There's nothing wrong with adding a period at the end of macro variable names. However, it's not the source of the problem here, and it won't change the error condition in this particular case.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.