BookmarkSubscribeRSS Feed
sahoositaram555
Pyrite | Level 9

Hi Experts,

I have a column such like below:

9  years
1  Week
0 6 year
1 0 Months

1  YEAR 7 MONTHS
5  YEARS
1  YEAR 6 MONTHS

I've some places double or single blanks in the ist space. I would like to remove the ist occuring space(if there are 2 spaces, 1 space to nospace. How to do achieve this? one such example could be:  1 0 years should be  10 years.

 

 

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16
You can use compbl function which will compress the double blanks to single blanks


compbl(var)
Thanks,
Jag
ChrisNZ
Tourmaline | Level 20

This will always remove the first space:

data WANT; 
  set HAVE;
  STR1 = prxchange('s/ //',1,STR);
run;
STR STR1
9  years 9 years
1  Week 1 Week
0 6 year 06 year
1 0 Months 10 Months
1  YEAR 7 MONTHS 1 YEAR 7 MONTHS
5  YEARS 5 YEARS
1 YEAR 6 MONTHS 1 YEAR 6 MONTHS

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 686 views
  • 1 like
  • 3 in conversation