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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 942 views
  • 2 likes
  • 3 in conversation