BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chinna0369
Pyrite | Level 9

Hi,

 

I am using hhmm. format for below ADTM variable.

snip1.PNG

 

But I am getting values differently as below.

snip 2.PNG

 

I would like to get time part as it is from ADTM variable, could you help me.

 

Thanks,

Adithya

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use the TOD format.

1735  data _null_;
1736  time='09:30't;
1737  put time= hhmm5.;
1738  put time= tod5.;
1739  run;

time=9:30
time=09:30

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Use the TOD format.

1735  data _null_;
1736  time='09:30't;
1737  put time= hhmm5.;
1738  put time= tod5.;
1739  run;

time=9:30
time=09:30
ballardw
Super User

First, your ADTM variable does not appear to be using an HHMM format. That would not display any date portion.

 

Example data is best presented as data step code because pictures can hide many sins, such as the possibility that ADTM is actually character and not a date, time or datetime value at all.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Since your COL4 is very obviously character it cannot be displayed in any time or date format. Without knowing the code used to build COL4 it may just be that you did not understand that the time value is rounded to the nearest minute when using simple HHMM format that defaults to 5 characters and as such rounds. If you want the seconds to appear then perhaps HHMM8. is what you want. I notice that every value of ADTM you show has 59 seconds, which is moderately suspicious by itself.

 

If you have a variable that is a SAS datetime value then you can extract the time portion with the TIMEPART function and then assign an HHMM format to that variable.

data example;
  x='01Jan2019:11:22:33'dt;
  /* demonstrate that a datetime value 
     does not display as desired
     with hhmm format
  */
  put x= x=datetime18. x=hhmm20.;
  y=timepart(x);
  /* display the time portion 
     with hhmm. format */
  put y= hhmm.;
run;

I am not even going to guess why you have stuff like ~n~{nbspace4}~m

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 420 views
  • 0 likes
  • 3 in conversation