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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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