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

Hi, I am trying to run a MACRO step to output multiple datasets based on the dates.  However, I can't seem to figure out how to mend the dates and create unique table names: 

 

%macro duo(rptmth);
proc sql;
create table P&rptmth as select * from dataset
where reportdate GE intnx('month',&rptmth.d,-12) and reportdate LT intnx('month',&rptmth.d,1)
quit;
%mend duo;
%duo('01Sep2015');
%duo('01May2015');

 

Thanks,

Jeff

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

If you were to include this statement as part of your program, you would immediately recognize that it won't work:

 

create table P'01Sep2015' as ...

 

That's all macro langauge is doing ... substituting text in order to generate the programming statements.  While you do require quotes for the date literals, you can't include them as part of the table names.  Instead, try calling the macro without quotes:

 

%duo (01Sep2015)

 

To make that work, you would have to add quotes for the date literals:

 

%macro duo(rptmth);
proc sql;
create table P&rptmth as select * from dataset
where reportdate GE intnx('month',"&rptmth."d,-12) and reportdate LT intnx('month',"&rptmth."d,1)
quit;
%mend duo;

 

Use double quotes, not single quotes, around macro variable references.  That's a requirement to permit macro language to resolve the values.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

If you were to include this statement as part of your program, you would immediately recognize that it won't work:

 

create table P'01Sep2015' as ...

 

That's all macro langauge is doing ... substituting text in order to generate the programming statements.  While you do require quotes for the date literals, you can't include them as part of the table names.  Instead, try calling the macro without quotes:

 

%duo (01Sep2015)

 

To make that work, you would have to add quotes for the date literals:

 

%macro duo(rptmth);
proc sql;
create table P&rptmth as select * from dataset
where reportdate GE intnx('month',"&rptmth."d,-12) and reportdate LT intnx('month',"&rptmth."d,1)
quit;
%mend duo;

 

Use double quotes, not single quotes, around macro variable references.  That's a requirement to permit macro language to resolve the values.

jeffbezos
Calcite | Level 5
Thank you!

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
  • 561 views
  • 1 like
  • 2 in conversation