The SAS Output Delivery System and reporting techniques

Datetime values in proc report

Reply
N/A
Posts: 0

Datetime values in proc report

Just realised I posted this in the wrong forum previously, I think it should go in this one...

Hello,

I want to show a datetime variable as two seperate columns for date and time using proc report. This can be done quite simply by adding another datastep before I do the proc report but this is too inefficient for large datasets.

Here is the code I have:
proc report data=shona.oos nowindows ;
column jtmdtid date time2 ;

define date/computed format=date9. "Date";
define time2/computed format=time8. "Time";
define jtmdtid/display "";

compute date;
date=datepart(jtmdtid);
endcomp;
compute time2;
time2=timepart(jtmdtid);
endcomp;
run;

But the problem is the compute blocks won't work unless I have variable jtmdtid in the column part. If I do that then the datetime variable is displayed in the report. I either a completely different way of converting datetime to date and time or else a way of hiding a variable that is specified as a column.

Any help is much appreciated.
SAS Super FREQ
Posts: 8,864

Re: Datetime values in proc report

Posted in reply to deleted_user
Hi:
If all you want are these simple formats for your date/time value, then you do not need to calculate those values in a compute block. You can do this with PROC REPORT:
[pre]
data mystuff;
infile datalines;
input name $ bday : datetime18.;
return;
datalines;
alan 15nov1950:07:53:45
bob 11oct1960:15:23:17
carl 23aug1958:10:18:34
;
run;

proc report data=mystuff nowd;
column name bday bday=time;
define name / display 'Name';
define bday / 'Birth Date' display f=dtdate9.;
define time / 'Birth Time' display f=tod10.;
run;
[/pre]


And you will get this output in the LISTING window:
[pre]
Birth
Name Date Birth Time
alan 15NOV1950 07:53:45
bob 11OCT1960 15:23:17
carl 23AUG1958 10:18:34

[/pre]

PROC REPORT allows the use of "aliases" in the COLUMN statement. So on this report, you would use the BDAY variable two times on the report row. The first time BDAY appears in the COLUMN statement, it appears with its own variable name. That means that the second time BDAY appears in the COLUMN statement, you are telling PROC REPORT that you need to use it a second time on the report row. To have a single variable appear more than one time on a report row, however, PROC REPORT expects that you will provide an ALIAS for the second (or third or fourth) usage. That's what the BDAY=TIME means in the COLUMN staement. So the first BDAY will be formatted using the DTDATE9. format (which will format only the DATE portion of a date/time variable value) and then the report item called TIME, (which is just an alias for BDAY) will be formatted with the TOD10. format.

It is only if you wanted OTHER date formats for BDAY that you would need to calculate a new column and use a COMPUTE block. An example of that code (but not the output is below).

cynthia

[pre]

ods listing;
proc report data=mystuff nowd;
column name bday calcdate bday=time ;
define name / display;
define bday / display noprint;
define calcdate /computed f=mmddyy10.;
define time / 'Birth Time' display f=tod10.;
compute calcdate;
calcdate = datepart(bday);
endcomp;
run;
[/pre]
Ask a Question
Discussion stats
  • 1 reply
  • 675 views
  • 0 likes
  • 2 in conversation