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

Hi

the have dataset is like the following (the name Liz has one blank space in front of it; Sam has / in front of it):

name     city     state

Liz        NY     NY

/Sam     SJ      NJ

Norm     LA     CA

Gloria    SC     MN

want to have the first non-alphabet character removed, so the table will be :

name     city     state

Liz          NY     NY

Sam       SJ      NJ

Norm     LA     CA

Gloria    SC     MN

what do you use to remove the unwanted characters/spaces?  Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Ajay
Fluorite | Level 6

Yea, compress.  Though it works on the whole string, not just the first letter.

data a;

input name $;

datalines;

Liz

/Sam

     nancy

/Gloria

;

run;

data b;

set a;

newname = compress(name,'/');

run;

View solution in original post

4 REPLIES 4
Reeza
Super User

Try the compress function with the appropriate modifiers or characters for your code.

name=compress(name, , 'kad');

http://support.sas.com/documentation/cdl/en/syntaxidx/64656/HTML/default/index.htm#/documentation/cd...

Can also look into the anypunct functions if you wanted as well.

Ajay
Fluorite | Level 6

Yea, compress.  Though it works on the whole string, not just the first letter.

data a;

input name $;

datalines;

Liz

/Sam

     nancy

/Gloria

;

run;

data b;

set a;

newname = compress(name,'/');

run;

Cyndia
Calcite | Level 5

Smiley Happy works for me!  thanks.

bharathkumar
Fluorite | Level 6

Hello,

 

You want to remove only special character. But before solution was it removes only "/" and also it compress all the "/".

please check this below solution.

 

data t;
infile cards;
input a $;
datalines;
/ag
a/g
ag/
/gh
;
run;

data t1;
set t;
if anyalpha(a) ne 1 then do;
a1=compress(a,substr(a,1,1));
end;
else a1=a;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 6715 views
  • 2 likes
  • 4 in conversation