Hi all,
I have a problem with implementing a DO loop using date variables as by-variable.
I have searched this community and found a way. But there comes an error when I tweak a little.
See the code first. This one works fine.
options symbolgen;
%macro daily00(X) /des = "Sample Macro";
%do i=1 %to 3;
%put &X._&i;
%end;
%mend daily00;
%macro iteration00(BeginDate, EndDate) /des = "Sample Macro";
%do j=%sysfunc(inputn(&begindate,date9.)) %to %sysfunc(inputn(&enddate,date9.));
%daily00(X=&j);
%end;
%mend iteration00;
%iteration00(BeginDate=23Dec2014, EndDate=24Dec2014);
Now I want to change the BeginDate and EndDate to YYYYMMDD, so in this case it would be 20141223 and 20141224, respectively.
I tried the below but something's wrong. I think I am confused with INPUT or INFORMAT syntax, but I am lost.
options symbolgen;
%macro daily00(X) /des = "Sample Macro";
%do i=1 %to 3;
%put &X._&i;
%end;
%mend daily00;
%macro iteration00(BeginDate, EndDate) /des = "Sample Macro";
%do j=%sysfunc(inputn(&begindate,8.)) %to %sysfunc(inputn(&enddate,8.));
%daily00(X=&j);
%end;
%mend iteration00;
%iteration00(BeginDate=20141223, EndDate=20141224);
The reason I am trying to use date format in this DO loop is because, I want to avoid numeric values such as 20141240 when calling datasets in the DAILY00 macro.
I am using SAS 9.4.
Any help is appreciated.
Yes, the informat is incorrect. You are using:
8.
But should be using:
yymmdd8.
Also note, you define %daily00 using X as a positional parameter. But your macro call uses it as a keyword parameter. Presumably that's just a typo.
Yes, the informat is incorrect. You are using:
8.
But should be using:
yymmdd8.
Also note, you define %daily00 using X as a positional parameter. But your macro call uses it as a keyword parameter. Presumably that's just a typo.
Thanks you. It works!
I was keep trying
yymmddn8.
since the numbers didn't have any usual delimiters such as / or -.
Anyway, thank you so much!
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 25. 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.