HI,
i have a report where I need to determine the time if its AM or PM .For example I have
time. ID
13:54 id1
10:33 Id2
i need to look at the time an determine if its AM like id2 is or PM like id1 is... The time is at military time ... In addition the number is coming in as a character
thAnks for your assistance
You don't mention the data source. It may be possible to modify the approach so that it is read as a SAS time value.
Currently as character:
if input(substr(time,1,2),f2) > 12 then AMPM='PM';
else AMPM='AM';
Assuming as military time you are getting 01:25 and not 1:25 for hours before 10.
If it's a time formatted variable, you can switch the format to an appropriate one that displays AM PM.
Or you can look at the hour. If the hour is >=12 then its PM, otherwise AM
if hour(time)>=12 then test="PM"; else "AM";
You don't mention the data source. It may be possible to modify the approach so that it is read as a SAS time value.
Currently as character:
if input(substr(time,1,2),f2) > 12 then AMPM='PM';
else AMPM='AM';
Assuming as military time you are getting 01:25 and not 1:25 for hours before 10.
hi ballardw,
i put in the code and I'm getting a error on f2. Something about formatted error thanks again
f2 should be f2. to reference the informat. Sorry about the typo.
data have;
input time $ ID $;
time_AM_PM=input(time,anydtdtm.);
format time_AM_PM TIMEAMPM.;
datalines;
13:54 id1
10:33 Id2
;
If you have a TIME variable then you can compare the time to a time literal.
IF TIME < '12:00't then AMPM='AM';
ELSE AMPM='PM';
You can convert the string to a time variable by using a INFORMAT;
time = informat(timestr,time5.);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: