BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidPhillips2
Rhodochrosite | Level 12

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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 🙂

View solution in original post

3 REPLIES 3
Astounding
PROC Star

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"

Reeza
Super User

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 🙂

Astounding
PROC Star

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1609 views
  • 2 likes
  • 3 in conversation