I'm trying to create additional rows based on time variable.
from time=0 to time=1, additional rows to be created with an increment of 0.1
from time=1 to time=3, additional rows to be created with an increment of 0.5.
Please find the input and output datasets below.
DATA HAVE;
INPUT ID TIME D1 D2 E1;
DATALINES;
1 -0.25 . . 0
1 0 . . 1
1 3 . . 0
1 672.25 . . 0
2 0 . . 0
2 0 . . 1
2 3 21300 9.966 0
2 669.5 2760 7.923 0
2 670.0833 . . 1
2 673.25 31400 10.355 0
2 1509.1667 3760 8.232 0
2 1509.1667 . . 1
2 1512.1667 24100 10.09 0
2 2181.4167 4170 8.336 0
2 2181.5 . . 1
2 2184.5333 26900 10.2 0
2 2853.5 . . 1
2 3525.7917 . . 1
2 3981.5 9310 9.139 0
;
DATA WANT;
INPUT ID TIME D1 D2 E;
DATALINES;
1 -0.25 . . 0
1 0 . . 1
1 0.2 . . 0
1 0.4 . . 0
1 0.6 . . 0
1 0.8 . . 0
1 1 . . 0
1 1.5 . . 0
1 2 . . 0
1 2.5 . . 0
1 3 . . 0
1 672.25 . . 0
2 0 . . 0
2 0 . . 1
1 0 . . 1
1 0.2 . . 0
1 0.4 . . 0
1 0.6 . . 0
1 0.8 . . 0
1 1 . . 0
1 1.5 . . 0
1 2 . . 0
1 2.5 . . 0
2 3 21300 9.966 0
2 669.5 2760 7.923 0
2 670.0833 . . 1
2 673.25 31400 10.355 0
2 1509.1667 3760 8.232 0
2 1509.1667 . . 1
2 1512.1667 24100 10.09 0
2 2181.4167 4170 8.336 0
2 2181.5 . . 1
2 2184.5333 26900 10.2 0
2 2853.5 . . 1
2 3525.7917 . . 1
2 3981.5 9310 9.139 0
;
Something like:
data have; input id time d1 d2 e1; datalines; 1 -0.25 . . 0 1 0 . . 1 1 3 . . 0 1 672.25 . . 0 2 0 . . 0 2 0 . . 1 2 3 21300 9.966 0 2 669.5 2760 7.923 0 2 670.0833 . . 1 2 673.25 31400 10.355 0 2 1509.1667 3760 8.232 0 2 1509.1667 . . 1 2 1512.1667 24100 10.09 0 2 2181.4167 4170 8.336 0 2 2181.5 . . 1 2 2184.5333 26900 10.2 0 2 2853.5 . . 1 2 3525.7917 . . 1 2 3981.5 9310 9.139 0 ; run; data want (drop=i); set have; if 0 <= time <= 1 then do; do i=time to 1 by 0.1; time=i; output; end; end; else if 1 < time <= 3 then do; do i=time to 3 by 0.5; time=i; output; end; end; else output; run;
@RW9: Thanks. In your code the increment from time=0 to time=1 by 0.1 works but not the time=1 to time=3 by 0.5. not sure why?
There is only one record in your test data which is within 1 and 3 and because that row is 3, do i=3 to 3 by 0.5 doesn't do anything.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.