Just realised I posted this in the wrong forum previously, I think it should go in this one...
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 ;
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.
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:
input name $ bday : datetime18.;
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.;
And you will get this output in the LISTING window:
Name Date Birth Time
alan 15NOV1950 07:53:45
bob 11OCT1960 15:23:17
carl 23AUG1958 10:18:34
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).