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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2494 views
  • 1 like
  • 2 in conversation