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