BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I want to create a series of dates from &start_date  till &end_date

What is the reason that I don't get it??

In the result there is only one date 05JUL2021

 

%let start_date=28JUN2021; %let end_date=04JUL2021; data wanted; date="&start_date"d; do while (date<="&end_date"d); date=intnx('day', date, 1, 's'); format date date9.; end; run;

 

4 REPLIES 4
singhsahab
Lapis Lazuli | Level 10

you have use output statement. 

 

%let start_date=28JUN2021; %let end_date=04JUL2021;
data wanted; 
date="&start_date"d; 
do while (date <"&end_date"d); 
date=intnx('day', date, 1, 's'); 
output;
format date date9.; end; run;
Patrick
Opal | Level 21

You missed the output statement. Because SAS dates are just a count of days since 1/1/1960 you even don't need the intnx() function for this.

%let start_date=28JUN2021;
%let end_date=04JUL2021;

data wanted;
  format date date9.;
  do date="&start_date"d to "&end_date"d;
    output;
  end;
  stop;
run;
Kurt_Bremser
Super User

You really, really, really need to start understanding the basic mechanics of the data step.

In the absence of an explicit OUTPUT statement, the data step compiler will code a single output at the "end" of the step. If there is implicit looping, caused by the presence of INFILE/INPUT (for external files) or SET/MERGE/UPDATE (for datasets), you will have one output at the end of every iteration of the step.

Since you do not read any data, there is only one iteration; since there also is no explicit OUTPUT statement, one single output will be performed, with the value of date that caused the termination of the DO WHILE loop.

novinosrin
Tourmaline | Level 20

%let start_date=%sysevalf('28JUN2021'd) ; 
%let end_date=%sysevalf('04JUL2021'd) ;

/*Horizontal*/
data temp/view=temp ;
  array dates(&start_date:&end_date) (&start_date:&end_date) ;
  format dates: date9. ;
run;

/*Vertical*/
proc transpose data=temp out=want(drop=_name_ rename=(col1=date)) ;
  var dates: ;
run;

proc print noobs ;run ;
date
28JUN2021
29JUN2021
30JUN2021
01JUL2021
02JUL2021
03JUL2021
04JUL2021

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 549 views
  • 1 like
  • 5 in conversation