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 :
Now, let us say i would like to define the values over the next 3 time intervals and I want something like this:
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.
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;
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;
@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.
That's it!
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.