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";
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!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.