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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 1138 views
  • 3 likes
  • 3 in conversation