Friday, 16 August 2013

Automating the starting date with a macro variable in SAS

Automating the starting date with a macro variable in SAS

Background: I have a code that pulls transactional data starting at the
beginning of the current calendar quarter, but from an year ago. For
example, if I run the code today (August 16, 2013) it will have to pull
all the data from July 1, 2012 onwards.
Problem: I want to automate the starting date for the data pull with a
macro variable.
So far, I'm stuck here:
%let ThisYear = %Sysfunc(Date(), YEAR.);
%let LastYear= %eval(&ThisYear-1); /* I get the starting year */
%let QTR_start_month= %eval(3*%Sysfunc(Date(), qtr.)-2); /* this gives me
the current quarter starting month. If I run it in August, it outputs 7
for July */
%let start_date=%str(01/%Sysfunc(month(&QTR_start_month))/&lcy);
The final macro variable outputs the date which I want, but in a format
which is not recognized by SAS.
I will greatly appreciate any help. Many thanks in advance!

No comments:

Post a Comment