Hi There,
I want to prepare dataset which has values for every 6 hours.
data new;
input loop dsstartdate ;
datalines;
1 1827705600
;
run;
data new2;
set new;
format dsstartdate datetime25.6;
run;
so my data looks like this
Loop DSSTARTDATE
1 01DEC2017:00:00:00.000000
And this is how I want
1 | 01DEC2017:00:00:00.000000 |
2 | 01DEC2017:06:00:00.000000 |
3 | 01DEC2017:12:00:00.000000 |
4 | 01DEC2017:18:00:00.000000 |
1 | 02DEC2017:00:00:00.000000 |
2 | 02DEC2017:06:00:00.000000 |
3 | 02DEC2017:12:00:00.000000 |
4 | 02DEC2017:18:00:00.000000 |
1 | 03DEC2017:00:00:00.000000 |
2 | 03DEC2017:06:00:00.000000 |
3 | 03DEC2017:12:00:00.000000 |
4 | 03DEC2017:18:00:00.000000 |
So Basically A loop through all the dates by every 6 hours. I was using intnx in a do loop
However somehow cant be able to crack it.
Anyhelp is appreaciated
A loop like this would work:
do dt = DSSTARTDATE to DSENDDATE by '06:00:00't;
output;
end;
Post the code you’ve tried please.
A loop like this would work:
do dt = DSSTARTDATE to DSENDDATE by '06:00:00't;
output;
end;
Thanks for the clue. Worked like a charm. Just in case if anyone needs the code.
data have;
input dsstartdate dsenddate;
cards;
1827705600 1861920000
;
run;
data want;
set have;
format dsstartdate dsenddate datetime25.6;
do dt = DSSTARTDATE to DSENDDATE by '06:00:00't;
if timepart(dt)=0 then
counter=1;
if timepart(dt)=21600 then
counter=2;
if timepart(dt)=43200 then
counter=3;
if timepart(dt)=64800 then
counter=4;
format dt datetime25.6;
output;
end;
keep dt counter;
run;
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 25. 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.