BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MadQuant
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

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.

MadQuant
Obsidian | Level 7

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!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2081 views
  • 1 like
  • 2 in conversation