BookmarkSubscribeRSS Feed
Yondori
Calcite | Level 5

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

111.png

2. And naturally it was converted to SAS like this (See Starttime variable)

2222.png

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.

3333.png

How can I make it right ? Please comment your generous help.

2 REPLIES 2
ballardw
Super User

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

Yondori
Calcite | Level 5

Thanks a bunch it works~!

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1295 views
  • 1 like
  • 2 in conversation