简体   繁体   中英

How to loop sas macro by date?

I defined a macro which get data of 1 day. For example

%macro getOneday(stnd_d);
data _null_;
    call symputx('numdate',&stnd_d.);
run;
data oneday&numdate;
   set alldata;
   where stdd = &stnd_d;
run;
%mend;

Now I want to loop that macro from start date to end date.

 data _null_;
    do i = '01mar2015'd to '30mar2015'd;
    %getOneday(stnd_d = i)
    end;
 run;

I don't know how can I pass the date expression value to %getOneday() as a parameter.

I hope you understand that macro - getOneday would simply write all the code written inside it, to the data _null_ statement by replacing the %getOneday and since you cannot write a data step inside a data step, its throwing an error. You simply have to replace the data _NULL_ statement with a macro like below. Also using date like that would not work as Macro would treat them as char , you will have to convert them into date format, before using them in %do loop.

%macro test;
data _null_;
date1='01mar2015'd;
date2='30mar2015'd;
call symputx("date1",date1);
call symputx("date2",date2);
run;
%put &date1.;
%put &date2.;

    %do i = &date1. %to &date2.;
    %getOneday(stnd_d = &i.)
    %end;

 %mend;

 %test;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM