Hi
I would like to know if anyone can help me with a macro loop I am having trouble with
I am trying to run the same macro for the weeks running Monday to Sunday for the past 2 years
/*2015*/
%line(29dec2014,04jan2015);%line(05jan2015,11jan2015);%line(12jan2015,18jan2015);%line(19jan2015,25jan2015);%line(26feb2015,01mar2015);%line(02mar2015,08mar2015);
%line(09mar2015,15mar2015);%line(16mar2015,22mar2015);%line(23mar2015,29mar2015);%line(30mar2015,05apr2015);%line(06apr2015,12apr2015);%line(13apr2015,19apr2015);
I am repeating the same lines several times but I am sure I can write a weekly macro loop to give the start and end dates so something that looks like
%macro new (Start, End);
.....i=1 to 60
j=1 to 60
%line(&i.,&j.)
%mend;
Thanks
Priya.
Call it from a data step:
data _null_;
date1 = '29dec2014'd;
do until (date1 > '13apr2015'd);
call execute('%line('!!put(date1,date9.)!!','!!put(date1+6,date9.)!!');');
date1 + 7;
end;
run;
Priya,
That should not be so difficult. I assume you want a macro to be called like %do_lines(01JAN2015,31DEC2016) - the parameters being starting date and ending date. I think this will work:
%macro do_lines(StartDate,EndDate);
%local Monday Sunday;
%do Monday=%sysfunc(intnx(WEEK.2,"&StartDate"d,0)) %to %sysfunc(inputn(&EndDate,date9.)) %by 7;
%let Sunday=%eval(&monday+6);
%line(%sysfunc(putn(&Monday,DATE9.)),%sysfunc(putn(&Sunday,DATE9.)));
%end;
%mend;
Regards,
Søren
Thankyou - This worked very well.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.