BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
shyamtawde
Fluorite | Level 6

if first.subject then do;
if dod ne . then enddt=strip(put(input(compress(dod,"-"),??date7.),??date9.));

showing below in log and enddt not populating.

Log:

321 data ex(drop=dod adt siteid);
322 set ex_srt;
323 /* format startdt enddt date9. starttm endtm time8.;*/
324 retain startdt starttm rfstdt enddt endtm rfendt;
325 by studyno subject dod;
326 if first.subject then do;
327 if dod ne . then enddt=strip(put(input(compress(dod,"-"),??date7.),??date9.));
328 if adt ne . then endtm=strip(adt);
329 /* if length(strip(endtm)) le 7 and index(endtm,":") eq 2 then
329! endtm="0"||strip(endtm); */
330 %dateder( indate=enddt, intime=endtm, outdt=rfendt);
331 /*rfstdt=input(strip(startdt||":"||starttm),??datetime20.);*/
332 end;
333
334 if last.subject then do;
335 if dod ne . then startdt=strip(put(input(compress(dod,"-"),??date7.),??date9.));
336 if adt ne . then starttm=strip(adt);
337 /* if length(strip(starttm)) le 7 and index(starttm,":") eq 2 then
337! starttm="0"||strip(starttm); */
338 %dateder( indate=startdt, intime=starttm, outdt=rfstdt);
339 /* rfendt=input(strip(enddt||":"||endtm),??datetime20.);*/
340 output;
341 end;
342 run;

NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
327:55 328:36 335:57 336:38
WARNING: The variable siteid in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: There were 112 observations read from the data set WORK.EX_SRT.
NOTE: The data set WORK.EX has 56 observations and 8 variables.

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

The problem seems to be that the DOD variable is numeric, and the COMPRESS function converts it to character. If it is numeric, it probably has a date or datetime format. But the COMPRESS function will not use that format, but a default format (I assume BEST32.) to convert it, and that will not give usable result when you try to read it with the INPUT function and informat DATE7.

 

You should probably change the code to

if dod ne . then enddt=put(dod,date9.);

if DOD is a date, and to

if dod ne . then enddt=put(datepart(dod),date9.);

if it is a datetime variable.

View solution in original post

4 REPLIES 4
s_lassen
Meteorite | Level 14

The problem seems to be that the DOD variable is numeric, and the COMPRESS function converts it to character. If it is numeric, it probably has a date or datetime format. But the COMPRESS function will not use that format, but a default format (I assume BEST32.) to convert it, and that will not give usable result when you try to read it with the INPUT function and informat DATE7.

 

You should probably change the code to

if dod ne . then enddt=put(dod,date9.);

if DOD is a date, and to

if dod ne . then enddt=put(datepart(dod),date9.);

if it is a datetime variable.

shyamtawde
Fluorite | Level 6

Thank you for your response and solution. code is working...

DOD variable is numeric which contents only dates.

 

 

Kurt_Bremser
Super User

Maxim 3: Know Your Data.

Know the type and (if assigned) display format of variables dod and adt. I guess they are already numeric, with a date/time format assigned, so the whole conversion process serves no purpose.

Kurt_Bremser
Super User

So you want to get the start and end datetimes of a process?

One easy step:

proc sql;
create table ex as
  select
    studyno,
    subject,
    min(dhms(dod,0,0,adt)) as start_datetime format=e8601dt19.,
    max(dhms(dod,0,0,adt) as end_datetime format=e8601dt19.
  from ex_srt
  group by studyno, subject
;
quit;

This step will sort the input table internally, so you can omit any preceding sort.

If your dates and times were already in a combined variable, you could use PROC SUMMARY:

proc summary data=ex_srt nway;
class studyno subject;
var datetime;
output out=ex (drop=_TYPE_ _FREQ_) min(datetime)=start_datetime max(datetime)=end_datetime;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 607 views
  • 3 likes
  • 3 in conversation