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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1029 views
  • 1 like
  • 3 in conversation