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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1829 views
  • 1 like
  • 2 in conversation