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
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 7840 views
  • 0 likes
  • 4 in conversation