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

Hi there

 

I am trying to convert this text so I can use the time element in SAS.?

 

12:30PM:Tuesday:Weekday

7:30AM:Tuesday:Weekday

6:60AM:Saturday:Weekend

 

 

 

currently stored as CHAR $25

 

I have managed to extract the time by doing the following but it is still text so cant use to sort by time 

 

time= Substr(text_,1,index(text_,"M:"));

 

 

How can I then convert to a SAS format

 

thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Apply a format.

 

format time_sas time8.;

View solution in original post

10 REPLIES 10
GreggB
Pyrite | Level 9

Your data needs a day, month and a year.

LK357
Obsidian | Level 7

The date sits in a separate text field 

 

September 1, 2015

GreggB
Pyrite | Level 9
Are you just wanting this?
12:30PM
7:30AM
.
.
LK357
Obsidian | Level 7

Hi yes and I have managed to get that but it is in a char format so when I sort by it, it's not sorting correctly... ie I need 7:30am before 12.30pm etc

GreggB
Pyrite | Level 9

not elegant but it works.

 

data one;
informat time $25. ;
input time ;
cards;
12:30PM:Tuesday:Weekday
7:30AM:Tuesday:Weekday
6:60AM:Saturday:Weekend
;
run;
data want;
set one;
time2=scan(time,1,'M')||'M';
run;
proc print;
run;

LK357
Obsidian | Level 7

Excellent thanks this works great Smiley LOL

Reeza
Super User

In general, the idea is the same as your earlier date question. Use input() with appropriate informat. 

Assuming you've isolated the time portiom correctly it will be something like:

 

Time_sas = input(time, time.);

LK357
Obsidian | Level 7

Thanks @Reeza that works and allows me to sort but is there a way of showing it in a format that is easy to understand ie 10:00AM and not 36000

Reeza
Super User

Apply a format.

 

format time_sas time8.;

LK357
Obsidian | Level 7

Excellent thank you!

 

 

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1898 views
  • 3 likes
  • 3 in conversation