BookmarkSubscribeRSS Feed
gzr2mz39
Quartz | Level 8
I want to remove the last 3 characters (i.e. :00) from a variable.
For example, how do I change these 3 observations:
8:00:00
7:45:00
10:00:00

to this format
8:00
7:45
10:00

Thank you.
4 REPLIES 4
p12937
Obsidian | Level 7
Here are a few options:
data t;
infile cards;
input t $8.;
length solution1 solution2 solution3 $5.;
solution1=scan(t,1,':')||':'||scan(t,2,':');
solution2=put(input(t,time8.),time5.);
solution3=reverse(substr(reverse(trim(left(t))),4));
cards;
8:00:00
7:45:00
10:00:00
;
Ksharp
Super User
What type is your variable? Numeric or Character?
[pre]



data t;
infile cards;
input t $8.;
time=put(input(t,time8.),hhmm5.);
cards;
8:00:00
7:45:00
10:00:00
;
run;
[/pre]


Ksharp
gzr2mz39
Quartz | Level 8
Numeric.
Your response and p12937's response were very helpful.
Thank you.
Patrick
Opal | Level 21
Hi

If the type is numeric then assigning another format like Ksharp showed would do:

format time hhmm5.;

HTH
Patrick

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 4 replies
  • 7015 views
  • 0 likes
  • 4 in conversation