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;
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;
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;
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.
%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 |
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.