0
votes

I'm a newbie in SAS. I would need help from the SAS community to optimize a SAS code I'm working on.

The current code is as follows:

%macro sales (outdata, date)

[
Create Table

Select data

%mend sales

]
/* The current code invokes macro manually as */

%Sales (Outdata = Sales_Aug, date = '2017-08-01');

%Sales (Outdata = Sales_Sept, date = '2017-09-01');

%Sales (Outdata = Sales_Oct, date = '2017-10-01');


/* So every month I've to manually enter last 3 months as input to the macro */

Is there a way, I can make the macro call dynamic? So that If I run the code in November, it selects data from last 3 months (Aug, Sept, Oct) and If I run the code in December, it gives data from Sept, Oct, Nov?

1
What have you tried? How are you currently using the date? Can you adopt the query to use a range of dates instead?Tom

1 Answers

0
votes

It is not hard to find the date that is the first day of the month that is three months before today. If you would like that date inside of single quotes and formatted in YYYY-MM-DD style then it is probably easier to do it with a data step.

data _null_;
  now=date();
  three_months_ago=intnx('month',now,-3,'b');
  call symputx('date',quote(put(three_months_ago,yymmdd10.),"'"));
run;