BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yashpande
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

A loop like this would work:

 

do dt = DSSTARTDATE to DSENDDATE by '06:00:00't;
    output;
    end;
PG

View solution in original post

3 REPLIES 3
Reeza
Super User

Post the code you’ve tried please. 

PGStats
Opal | Level 21

A loop like this would work:

 

do dt = DSSTARTDATE to DSENDDATE by '06:00:00't;
    output;
    end;
PG
yashpande
Obsidian | Level 7

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 1323 views
  • 1 like
  • 3 in conversation