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";
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.