Date stamp manipulation question.

Reply
N/A
Posts: 0

Date stamp manipulation question.

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: Date stamp manipulation question.

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.
N/A
Posts: 0

Re: Date stamp manipulation question.

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;
Super Contributor
Posts: 359

Re: Date stamp manipulation question.

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;
N/A
Posts: 0

Re: Date stamp manipulation question.

Thanks FliP for pointing out the mistake...
N/A
Posts: 0

Re: Date stamp manipulation question.

Thanks Flip for pointing out the mistake...
Post a Question
Discussion Stats
  • 5 replies
  • 451 views
  • 0 likes
  • 3 in conversation