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

/**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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 126 views
  • 0 likes
  • 3 in conversation