BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
thanikondharish
Calcite | Level 5

/**rawdata set looks like below*/

data rawdata ;

text="essay, an analytic, interpretative, or critical literary composition usually much shorter and less systematic and

formal than a dissertation or thesis

 

and usually dealing with its subject from a limited and often personal point of view";

run;

 

i have one rawdata like above one . with in a string we have multiple empty lines,tab spaces, unwanted spaces . How to remove all type of spaces except single embbded space. 

I tried with few programs but I couldn't . coming like few words going to mix for example see bold letters 'and' 'formal' these words coming like "andformal".

My request is 

The record should be like below if export this dataset:
"essay, an analytic, interpretative, or critical literary composition usually much shorter and less systematic and formal than a dissertation or thesis and usually dealing with its subject from a limited and often personal point of view"

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

I cannot tell from your share code what your variable actually contains.

 

If it just has spaces, as your code would generate, then just use COMPBL() to collapse the multiple adjacent spaces into one.

 

If it actual does have other invisible characters ( such as null, tab, line feed, carriage return, form feed, or non-breaking space) then first convert them into spaces.

 

data want;
  set rawdata;
  text = compbl(translate(text,' ','00090A0D0CA0'x));
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

I cannot tell from your share code what your variable actually contains.

 

If it just has spaces, as your code would generate, then just use COMPBL() to collapse the multiple adjacent spaces into one.

 

If it actual does have other invisible characters ( such as null, tab, line feed, carriage return, form feed, or non-breaking space) then first convert them into spaces.

 

data want;
  set rawdata;
  text = compbl(translate(text,' ','00090A0D0CA0'x));
run;
Ksharp
Super User
data rawdata ;
text='090D0A'x||"essay, an analytic, interpretative, or ";


length want $ 2000;
want=compbl(prxchange('s/[\f\n\r\t\v]//',-1,text));
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 508 views
  • 0 likes
  • 3 in conversation