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 |
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: