BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1190 views
  • 1 like
  • 5 in conversation