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

All, 
   I am looking to understand how to expand a SAS dataset ? So, let us look at the following example 

 

Data Test; 
	set Sashelp.timedata(obs = 3); 
Run; 

  The above would yield the following : 

image.png

 

    Now, let us say i would like to define the values over the next 3 time intervals and I want something like this: 

image.png

 

  In this example, volume has the relation of being 1.5 times of the previous rows and the the datetime is just uniform with 30 minute interval. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Well, I don't think your math is right regarding multiplying by 1.5 ... however in general this should work ... by adding 30*60 to the datatime, that's 30 minutes converted to seconds (by multiplying by 60).

 

data test.
    set sashelp.timedata(obs=3) end=eof;
    output;
    if eof then do 1 = 1 to 3;
         volume=volume*1.5;
         datetime=datetime+30*60;
         output;
    end;
run;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Well, I don't think your math is right regarding multiplying by 1.5 ... however in general this should work ... by adding 30*60 to the datatime, that's 30 minutes converted to seconds (by multiplying by 60).

 

data test.
    set sashelp.timedata(obs=3) end=eof;
    output;
    if eof then do 1 = 1 to 3;
         volume=volume*1.5;
         datetime=datetime+30*60;
         output;
    end;
run;
--
Paige Miller
UdayGuntupalli
Quartz | Level 8

@PaigeMiller
    Thank you. When I dragged the formula over in Excel for the screenshot, I believe it got incremented. However, I get the idea of what you are proposing. I noticed a few errors in the code you provided: 

 

data test; * This i believe is not a period and a semicolon; 
    set sashelp.timedata(obs=3) end=eof;
    output;
    if eof then do i = 1 to 3;   *I don't think this is 1 = 1 to 3 but i = 1 to 3; 
         volume=volume*1.5;
         datetime=datetime+30*60;
         output;
    end;
run;

Assuming this is what you were recommending, it works. 

PaigeMiller
Diamond | Level 26

That's it!

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1608 views
  • 1 like
  • 2 in conversation