So I want to build a macro that has two dates. The first date is the starting day. The second date is the ending day. If the ending day is on a Saturday and it is the first day of the month, then I want date2 to increase 1 day to be '02OCT2016'd in the example below. Otherwise the date2 would be what is listed in the mend statement.
There is code for pulling data in between, but that is not the problem. Using SAS enterprise guide 6.1 and sas 9.4.
%MACRO flash (cy,date1,date2);
data _null_;
if weekday("&date2"d) = 7 and day("&date2"d) eq 1 then date2 = intnx('day',date2,1);
RUN;
proc sql;
create table test1 as
select a.*, b.*
from table 1, table2
where rdate ge "&date1"d and rdate le "&date2"d;
QUIT;
%MEND;
%FLASH (1,'02SEP2016'd,'01OCT2016'd);
%FLASH (2,'03SEP2016'd,'02OCT2016'd);
I would recommend than instead of
%FLASH (1,'02SEP2016'd,'01OCT2016'd);
That you use
%FLASH (1,02SEP2016,01OCT2016);
because you are referencing things in the form of "&date2"d in the code.
And if this is debug code:
if weekday("&date2"d) = 7 and day("&date2"d) eq 1 then date2 = intnx('day',date2,1);
You may want
if weekday("&date2"d) = 7 and day("&date2"d) eq 1 then date2 = intnx('day',"&date2"d,1);
Put date2 date9.; /*< to display the data step variable value to you*/
Assuming that you actually will want to add a CALL SYMPUTX('DATE2',put(date2,date9.)) after you get the logic working correctly
I would recommend than instead of
%FLASH (1,'02SEP2016'd,'01OCT2016'd);
That you use
%FLASH (1,02SEP2016,01OCT2016);
because you are referencing things in the form of "&date2"d in the code.
And if this is debug code:
if weekday("&date2"d) = 7 and day("&date2"d) eq 1 then date2 = intnx('day',date2,1);
You may want
if weekday("&date2"d) = 7 and day("&date2"d) eq 1 then date2 = intnx('day',"&date2"d,1);
Put date2 date9.; /*< to display the data step variable value to you*/
Assuming that you actually will want to add a CALL SYMPUTX('DATE2',put(date2,date9.)) after you get the logic working correctly
You own it..I just designed a sample one to test it for reference.
data table1 ;
input ID DOB ddmmyy10.;
datalines ;
1 02/10/2016
5 03/10/2016
;
run ;
data table2 ;
input ID DOB ddmmyy10.;
datalines ;
1 02/10/2016
5 03/10/2016
;
run ;
%MACRO flash (cy,date1,date2);
data _null_;
if weekday("&date2"d) = 7 and day("&date2"d) eq 1 then date2 = intnx('day',date2,1);
RUN;
%put &date2 ;
proc sql;
create table test1 as
select a.id,a.DOB format=date9.
from table1 as a , table2 as b
where a.DOB ge "&date1."d and a.DOB le "&date2."d;
QUIT;
%MEND;
%FLASH (1,02SEP2016,01OCT2016);
%FLASH (1,03SEP2016,02OCT2016);
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.