BookmarkSubscribeRSS Feed
PrinceAde
Obsidian | Level 7

Hi everyone, I have challenge formating time.
I'm trying to create time format from time().
For example, I want it in 5:25(I don't want pm or am attached to time). What I'm getting is either 5:25pm and 17:25.
data _null_;

call symputx('time', put(time, tod5.));

run;

%put &=time;

I have tried using time5. timeampm. as  well. 
None is working.
What can I do please?

2 REPLIES 2
Tom
Super User Tom
Super User

Since you seem to be putting the value into a macro variable just add more logic.

Either after you have converted the time into a string.

1    data _null_;
2      time='17:25't ;
3      call symputx('time', substr(put(time, timeampm.),1,5));
4    run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


5    %put &=time;
TIME=5:25
6

Or before

7    data _null_;
8      time='17:25't ;
9      call symputx('time', put(mod(time,'12:00:00't), time5.));
10   run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


11   %put &=time;
TIME=5:25

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1479 views
  • 2 likes
  • 3 in conversation