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

Hi,

 

I'm being tasked with updating a lot of SAS programs due to a change in Dataset name configuration on our servers.

 

Traditonally a series of datasets were stored each month within their own databases. The specific datasets were given the same name within each database. So for example in Freeze_month1 there would be a dataset called Activ. For Freeze_month2 there would be a dataset called activ.

 

This meant that the same code could be run each month just by modifying the libname reference to point to Freeze_month1 or Freeze_month2.

They are now storing all data within the same database but as activ_m1 or activ_m2.

 

I was hoping to create a variable containing the 'month' element of the dataset and append that to the 'activ' element.

 

So the code would look something like

 

libname DB1 odbc dsn='database';

%let mnth ='M1';

 

data aa;

set DB1.activ&mnth;

run;

 

This would then translate to DB1.activ_M1 

 

I've tried using various quotes but without success.

 

Any help would be appreciated as I'm using SAS9.4.

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You need to examine the text which is generated from using macro, try this:

%let mnth ='M1';

%put db1.activ&mnth;

 

What this will show you is that the code you are generating looks like this:

db1.activ'M1'

 

This is invalid, first the quotes in the macro variable mess it up, and secondly you miss the underscore.  Change to:

%let mnth=M1;

%put db1.activ_&mnth.;

 

And the dataset name will be generated correctly.

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You need to examine the text which is generated from using macro, try this:

%let mnth ='M1';

%put db1.activ&mnth;

 

What this will show you is that the code you are generating looks like this:

db1.activ'M1'

 

This is invalid, first the quotes in the macro variable mess it up, and secondly you miss the underscore.  Change to:

%let mnth=M1;

%put db1.activ_&mnth.;

 

And the dataset name will be generated correctly.

Brian_lewis67
Calcite | Level 5

That worked perfectly.

 

It was the single quotes that threw me.

 

Thanks very much for such a quick reply

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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