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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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