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);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: