Hi All,
I have a time variable that is in the format of timeampm11.
ex:12:48:06 AM
How do I extract the "AM" from the time value? I have tried the following code none of them worked:
if index(timestamp, 'AM') then td = "AM";
if scan(timestamp,3," ") eq "AM" then td = "AM";
Thank you!
if index(vvalue(timestamp), 'AM') then td = "AM";
Or an approach with a custom format:
proc format library=work; picture myampm low - high ='%p' (datatype=time) ; run; data exammple; input x :time5.; td = put(x,myampm.); datalines; 00:01 10:15 14:25 23:59 ; run;
Or just use the format as needed with your existing variable.
if index(vvalue(timestamp), 'AM') then td = "AM";
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.