BookmarkSubscribeRSS Feed
yonib
SAS Employee
If I have this obs: yyy"y www qqq and i want to get yyyy without the space,
what should i do?
6 REPLIES 6
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Use the COMPRESS function in a SAS DATA step.

Scott Barry
SBBWorks, Inc.
yonib
SAS Employee
It will not solve my problem beacuse if i have yyy"y www qqq and
I will use compress(translate(var,' ' ,'"'));
The result will be this:yyyywwwqqq
And this is not what im looking for.....
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Read the DOC on the COMPRESS function and you will see that you can supply the specific character(s) to be compressed.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
use input them to indicate the line number
data temp;
input y 1-5 m ...;
then use compress to compress the variable y
them combine them in the way you like
Patrick
Opal | Level 21
The following code does what you asked for.
data _null_;
have='yyy y www qqq ';
have=tranwrd(have,'y y','yy');
put have=;
want=scan(have,1);
put want=;
run;

More general solutions would be possible - especially with RegEx - but you would have to tell us a bit more in detail what the problem is about you want to solve.
yonib
SAS Employee
Patrick and Sbb ,
Thanks alot for your program ideas.
thay help me alot!!!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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