BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I have a raw dataset with 200 observations.There is a date and time variable which records date and time when the patient information was entered into the database.
For every record that is entered the time increments my seconds or minutes .
I need to create a new variable Time which should have the value of the first record entered across all observations of the same date.
eg. if 10 records were entered on jan 2 2010 starting at 11.23.23 (time) all 10 records should have the same value of time.When date changes to jan 3 2010 then the first value of time should repeat across observations and so on.
I am stuck in trying to repeat the observation. Can any one please help.

Thanks for your time.

Regards,
Jessica.
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You should consider BY GROUP PROCESSING within a SAS DATA step, while using a RETAIN statement for capturing your first occurence of a "time" within a given "date".

Search the SAS support website http://support.sas.com/ for detailed SAS-hosted documentation and supplemental technical reference material on the topic.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Hi Jessi,
Following program will help you to resolve your problem.
DATA abs;
INPUT
Name : $8.
Date : date9.
Time : Time5.
;
DATALINES;
abc 27-Jan-01 0:55
abc 27-Jan-01 1:10
abc 27-Jan-01 2:10
abc 27-Jan-01 3:10
bcd 28-Jan-01 4:10
bcd 28-Jan-01 5:10
bcd 28-Jan-01 6:10
bcd 28-Jan-01 7:10
bcd 28-Jan-01 8:10
bcd 28-Jan-01 9:10
bcd 28-Jan-01 10:10
bcd 28-Jan-01 11:10
efg 29-Jan-00 12:10
efg 29-Jan-00 13:10
efg 29-Jan-00 14:10
efg 29-Jan-00 15:10
efg 29-Jan-00 16:10
efg 29-Jan-00 17:10
efg 29-Jan-00 18:10
;

PROC SORT DATA=abs;
BY Name Date;
RUN;

DATA newabs;
RETAIN IniTime;
SET abs;
BY Name Date;
IF FIRST.date THEN
IniTime = Time;

RUN;
Flip
Fluorite | Level 6
Arul;

You commited the carnal sin of first. processing. Not sorting by one variable past what you are looking at the first. of. By moving datalines in your program it no longer works. You are depending on the times being in the correct order before the sort.
Run the below, and you will see the wrong results, you MUST use
BY Name Date Time; to get the correct results all the time.


DATA abs;
INPUT
Name : $8.
Date : date9.
Time : Time5.
;
DATALINES;
abc 27-Jan-01 3:10
abc 27-Jan-01 0:55
abc 27-Jan-01 1:10
abc 27-Jan-01 2:10
bcd 28-Jan-01 4:10
bcd 28-Jan-01 5:10
bcd 28-Jan-01 6:10
bcd 28-Jan-01 7:10
bcd 28-Jan-01 8:10
bcd 28-Jan-01 9:10
bcd 28-Jan-01 10:10
bcd 28-Jan-01 11:10
efg 29-Jan-00 15:10
efg 29-Jan-00 12:10
efg 29-Jan-00 13:10
efg 29-Jan-00 14:10
efg 29-Jan-00 16:10
efg 29-Jan-00 17:10
efg 29-Jan-00 18:10
;

PROC SORT DATA=abs;
BY Name Date ;
RUN;

DATA newabs;
RETAIN IniTime;
SET abs;
BY Name Date ;
IF FIRST.date THEN
IniTime = Time;
RUN;
deleted_user
Not applicable
Thanks FliP for pointing out the mistake...
deleted_user
Not applicable
Thanks Flip for pointing out the mistake...

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 5 replies
  • 1312 views
  • 0 likes
  • 3 in conversation