Programming the statistical procedures from SAS

Help : Day formatting Problem

Occasional Contributor
Posts: 16

Help : Day formatting Problem

Hi I have some questions about formatting.

Anyone who can handle this

please comment.

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.

Super User
Posts: 10,871

Re: Help : Day formatting Problem

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.);

Occasional Contributor
Posts: 16

Re: Help : Day formatting Problem

Thanks a bunch it works~!

Ask a Question
Discussion stats
  • 2 replies
  • 1 like
  • 2 in conversation