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


Hi,

I am trying to use macro to do a one year forward performance track for the origination period 201202 - 201207. So if the origination month is 201202, i will track the month from 201202 to 201301 to see how origination performs. After I run the code, there is warning ' This SAS global statement is not support in proc sql' which causes my proc sql not working properly.

%macro monthly (first,last);

%do mon=&first &to &last;

%let monthend=%eval(&mon+99);

proc sql;

create table test&mon as

select*

from aaa_&mon as a left join master_file

on num=num;

where &mon<=YEAR_MONTH<=&monthend;

quit;

%end;

%mend monthly;

%monthly(201202,201207);

Have any idea what causes the warning?

Thanks in advance!

Frank

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

I believe the %do block is not correct, you have used &to instead of %to. Please check and change it to %to.

also remove the semicolon after num=num; i.e., before the where clause.

Please check the updated code below

%macro monthly (first,last);

%do mon=&first %to &last;

%let monthend=%eval(&mon+99);

proc sql;

create table test&mon as

select*

from aaa_&mon as a left join master_file as b

on a.num=b.num

where &mon<=YEAR_MONTH<=&monthend;

quit;

%end;

%mend monthly;

%monthly(201202,201207);

Thanks,

Jagadish

Thanks,
Jag

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

I believe the %do block is not correct, you have used &to instead of %to. Please check and change it to %to.

also remove the semicolon after num=num; i.e., before the where clause.

Please check the updated code below

%macro monthly (first,last);

%do mon=&first %to &last;

%let monthend=%eval(&mon+99);

proc sql;

create table test&mon as

select*

from aaa_&mon as a left join master_file as b

on a.num=b.num

where &mon<=YEAR_MONTH<=&monthend;

quit;

%end;

%mend monthly;

%monthly(201202,201207);

Thanks,

Jagadish

Thanks,
Jag
zhige50
Obsidian | Level 7

Thanks so much. It works now!

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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