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

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 750 views
  • 1 like
  • 3 in conversation