BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hein68
Obsidian | Level 7

Hello.  I'm stuck and would appreciate your help.

 

I have a character variable that has times that look like this:

12:00:00 AM

12:01:00 AM

12:02:00 AM etc.

 

I want to convert them to a time value that assigns 0:00:00 for 12:00:00 AM through 23:59:00 for 11:59 PM.  What do I need to do?

 

I use SAS Enterprise Guide 7.1 or SAS 9.4.

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@hein68 wrote:

Hello.  I'm stuck and would appreciate your help.

 

I have a character variable that has times that look like this:

12:00:00 AM

12:01:00 AM

12:02:00 AM etc.

 

I want to convert them to a time value that assigns 0:00:00 for 12:00:00 AM through 23:59:00 for 11:59 PM.  What do I need to do?

 

I use SAS Enterprise Guide 7.1 or SAS 9.4.

 

Thanks!

 


The example below should help. You would use a data step with a set statement to reference your existing data and the input function should reference your character time variable. The datalines is to create values to display the code working. The format is so the value displays as time and not just the number of seconds represented.

 

data example;
   input char_text $ 1-11 ;
   timevar= input (char_text,time11.);
   format timevar timeampm11.;
datalines;
12:00:00 AM
12:01:00 AM
12:00:00 PM
12:01:00 PM
;
run;

View solution in original post

4 REPLIES 4
ballardw
Super User

@hein68 wrote:

Hello.  I'm stuck and would appreciate your help.

 

I have a character variable that has times that look like this:

12:00:00 AM

12:01:00 AM

12:02:00 AM etc.

 

I want to convert them to a time value that assigns 0:00:00 for 12:00:00 AM through 23:59:00 for 11:59 PM.  What do I need to do?

 

I use SAS Enterprise Guide 7.1 or SAS 9.4.

 

Thanks!

 


The example below should help. You would use a data step with a set statement to reference your existing data and the input function should reference your character time variable. The datalines is to create values to display the code working. The format is so the value displays as time and not just the number of seconds represented.

 

data example;
   input char_text $ 1-11 ;
   timevar= input (char_text,time11.);
   format timevar timeampm11.;
datalines;
12:00:00 AM
12:01:00 AM
12:00:00 PM
12:01:00 PM
;
run;
hein68
Obsidian | Level 7
Yes, this worked. Thanks so much!


TomKari
Onyx | Level 15

To do it with the tasks in EG, create a query, create a new advanced expression, and use the functions combination that @ballardw shows you.

 

Tom

hein68
Obsidian | Level 7
Thanks so much!


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 736 views
  • 0 likes
  • 3 in conversation