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-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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