Hello, I have a dataset that has multiple names separated by '?' in single column. I was able to separate them but some of them have multiple '?' in front of them. Is there a way I can trim only the first '?' from the character name and not the others?
X= ?????BLAIN_BRUCE?CONOVER_SCOTTD?BEARDWOOD_JOHNP
I only want to remove ? from the beginning and not others. so I want the output to look like
BLAIN_BRUCE?CONOVER_SCOTTD?BEARDWOOD_JOHNP
x2=compress(x,'?') ;
But this compress removes all ?. I know there is a Btrim function but I would like to use it in data step. Is there anything I can do?
Hi @mjizzle
data want;
X="?????BLAIN_BRUCE?CONOVER_SCOTTD?BEARDWOOD_JOHNP";
Want=substr(x,verify(x,'?'));
run;
If the above works, though simple as it looks, I owe my sincere gratitude to Guru/Master @data_null__ for tons of incredibly overwhelming variety of solutions in his SAS-L posts. I recommend reading his posts
Try the LEFT function.
Tried it, but doesnt it only work for removing spaces?
Hi @mjizzle
data want;
X="?????BLAIN_BRUCE?CONOVER_SCOTTD?BEARDWOOD_JOHNP";
Want=substr(x,verify(x,'?'));
run;
If the above works, though simple as it looks, I owe my sincere gratitude to Guru/Master @data_null__ for tons of incredibly overwhelming variety of solutions in his SAS-L posts. I recommend reading his posts
Alternatively,
data test;
X= "?????BLAIN_BRUCE?CONOVER_SCOTTD?BEARDWOOD_JOHNP";
do until (scan(x,1,'?','m')^="");
x=substr(x,2);
end;
run;
Hi @SuryaKiran I suppose this problem is rather much too simple and straight forward.
You could consider
Want=substr(x,(notpunct(x)));
Want=substr(x,(anyalnum(x)));
and there are many more related approaches so forth.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.