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.
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;
Try the compress function with the appropriate modifiers or characters for your code.
name=compress(name, , 'kad');
Can also look into the anypunct functions if you wanted as well.
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;
works for me! thanks.
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;
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.
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.