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

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