BookmarkSubscribeRSS Feed
Nsas
Calcite | Level 5

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
;

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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; 
Nsas
Calcite | Level 5

@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?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 702 views
  • 0 likes
  • 2 in conversation