Hi,
I'm a SAS newbie. I have a time variable (TIME) that is in milliseconds but I want to create a new variable (PERIOD) that tells me which minute during the day the observation falls within, while keeping all the original observations. The data runs from 8AM to 4.30PM.
For example, I would like between 08:00:00 and 08:01:00 to be Period = 1 and between 16:29:00 and 16:30:00 to be Period = 510.
The starting few lines of my current solution is below and as you can understand, this continues for another 500 odd lines. Can anyone suggest a more sophisticated solution?
data work.x; set work.x;
if TIME >= '08:00:00' and TIME < '08:01:00' then PERIOD = 1;
else if TIME >= '08:01:00' and TIME < '08:02:00' then PERIOD = 2;
else if TIME >= '08:02:00' and TIME < '08:03:00' then PERIOD = 3;
else if TIME >= '08:03:00' and TIME < '08:04:00' then PERIOD = 4;
else if TIME >= '08:04:00' and TIME < '08:05:00' then PERIOD = 5;
else if TIME >= '08:05:00' and TIME < '08:06:00' then PERIOD = 6;
else if TIME >= '08:06:00' and TIME < '08:07:00' then PERIOD = 7;
else if TIME >= '08:07:00' and TIME < '08:08:00' then PERIOD = 8;
else if TIME >= '08:08:00' and TIME < '08:09:00' then PERIOD = 9;
else if TIME >= '08:09:00' and TIME < '08:10:00' then PERIOD = 10;
else if TIME >= '08:10:00' and TIME < '08:11:00' then PERIOD = 11;
... etc.
else if TIME >= '16:29:00' and TIME < '16:30:00' then PERIOD = 510;
else PERIOD = 511;
run;
I'm a SAS newbie. I have a time variable (TIME) that is in milliseconds but I want to create a new variable (PERIOD) that tells me which minute during the day the observation falls within, while keeping all the original observations. The data runs from 8AM to 4.30PM.
For example, I would like between 08:00:00 and 08:01:00 to be Period = 1 and between 16:29:00 and 16:30:00 to be Period = 510.
The starting few lines of my current solution is below and as you can understand, this continues for another 500 odd lines. Can anyone suggest a more sophisticated solution?
data work.x; set work.x;
if TIME >= '08:00:00' and TIME < '08:01:00' then PERIOD = 1;
else if TIME >= '08:01:00' and TIME < '08:02:00' then PERIOD = 2;
else if TIME >= '08:02:00' and TIME < '08:03:00' then PERIOD = 3;
else if TIME >= '08:03:00' and TIME < '08:04:00' then PERIOD = 4;
else if TIME >= '08:04:00' and TIME < '08:05:00' then PERIOD = 5;
else if TIME >= '08:05:00' and TIME < '08:06:00' then PERIOD = 6;
else if TIME >= '08:06:00' and TIME < '08:07:00' then PERIOD = 7;
else if TIME >= '08:07:00' and TIME < '08:08:00' then PERIOD = 8;
else if TIME >= '08:08:00' and TIME < '08:09:00' then PERIOD = 9;
else if TIME >= '08:09:00' and TIME < '08:10:00' then PERIOD = 10;
else if TIME >= '08:10:00' and TIME < '08:11:00' then PERIOD = 11;
... etc.
else if TIME >= '16:29:00' and TIME < '16:30:00' then PERIOD = 510;
else PERIOD = 511;
run;