BookmarkSubscribeRSS Feed
Neptun83
Calcite | Level 5

Hello !

I would like to delete all single character (between two spaces)in a column. 

For example : test h text2 z

In this example I would like to delete 'h' and 'z'.

 

Thank you, if you can help me. 

I use SAS EG 8.2.4.

3 REPLIES 3
Tom
Super User Tom
Super User

The version of Enterprise Guide should not matter since you will have to use actual SAS code for this.  And it should not matter what version of SAS you are using.

 

You could probably construct a regular expression that would do it.

 

But here is a method using regular SAS functions, COUNTW(), SCAN() and CATX().

data want;
  set have;
  newvar=oldvar;
  newvar=' ';
  do i=1 to countw(oldvar,' ');
    if length(scan(oldvar,i,' '))>1 then newvar=catx(' ',newvar,scan(oldvar,i,' '));
  end;
run;

 

Patrick
Opal | Level 21

Here an approach using a regular expression

data have;
  infile datalines truncover;
  input str $40.;
  datalines;
test h text2 z
a b test h text2 z
test h text2
;

data want; 
  set have;
  length str2 $40;
  str2=prxchange('s/\b\w\b\s?//oi',-1,str);
run;

 

Neptun83
Calcite | Level 5

Thank you for the replies guys! Both of them were very useful for me! 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 698 views
  • 3 likes
  • 3 in conversation