01-16-2013 02:46 AM
Hi I have some questions about formatting.
Anyone who can handle this
1. From the excel data as follows I imported it to SAS data set
2. And naturally it was converted to SAS like this (See Starttime variable)
3. What I want to do is to extract the ‘DAY’ from the Starttime variable.
(e.g. if the starttime record is 2012-07-05 18:41 then I want to make it represented like '05' just day! )
And to do that, I wrote code like this. But it doesn’t really work at all.
data yhg0; set yhg; format starttime day4.; run;
if I use the code above. SAS shows me the result like this which I don't really expect.
How can I make it right ? Please comment your generous help.
01-16-2013 11:08 AM
SAS probably imported the value as a SAS datetime variable. Try displaying the value with a DATETIME20. variable. HINT: you can do this in Viewtable by clicking on the column heading and changing the format in the properties.
How critical is the leading 0 in the day? Do you need in display or to manipulate? To get a numeric value of the day of the month from a datetime variable:
DayOfMonth = day(datepart(starttime));
You could assign the a Z format so it displays with a leading zero: Format DayOfMonth z2.;
or create a character variable
DayOfMonth = put(day(datepart(starttime)),z2.);