DATA Step, Macro, Functions and more

translate without spacing

Reply
SAS Employee
Posts: 105

translate without spacing

If I have this obs: yyy"y www qqq and i want to get yyyy without the space,
what should i do?
Super Contributor
Super Contributor
Posts: 3,176

Re: translate without spacing

Use the COMPRESS function in a SAS DATA step.

Scott Barry
SBBWorks, Inc.
SAS Employee
Posts: 105

Re: translate without spacing

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.....
Super Contributor
Super Contributor
Posts: 3,176

Re: translate without spacing

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.
Not applicable
Posts: 0

Re: translate without spacing

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
Respected Advisor
Posts: 4,736

Re: translate without spacing

Posted in reply to deleted_user
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.
SAS Employee
Posts: 105

Re: translate without spacing

Patrick and Sbb ,
Thanks alot for your program ideas.
thay help me alot!!!
Ask a Question
Discussion stats
  • 6 replies
  • 176 views
  • 0 likes
  • 4 in conversation