BookmarkSubscribeRSS Feed
MarcTC
Obsidian | Level 7
I am wondering if there is a simple statement which can do the following conversion.

If a string begins with X's, then get rid of all initial X's.

Some examples here:

XDANO => DANO
XXQRX => QRX
XMKR => MKR
XXXDMZ => DMZ
CANE => CANE
4 REPLIES 4
chang_y_chung_hotmail_com
Obsidian | Level 7
Here is one way.



   data _null_;


     length x y $8;


     do x = """A""XDANO""XXQRX""XMKR";


       y = prxchange("s|^X+||",1,x);


       put x= @10 y=;


     end;


   run;


   /* on log


   x=       y=


   x=A      y=A


   x=XDANO  y=DANO


   x=XXQRX  y=QRX


   x=XMKR   y=MKR


   */

MarcTC
Obsidian | Level 7
Thanks, this is great!
RickM
Fluorite | Level 6
Here is another solution.

Good luck!

[pre]
data one;
input names $;
datalines;
XDANO
XXQRX
XMKR
XXXDMZ
CANE
;

data two;
set one;
do while (upcase(char(names,1)) eq "X");
names=substr(names,2);

end;
run;
[/pre]
Ksharp
Super User
Hi.
I have another choice.


[pre]
data one;
input names $;
datalines;
XDANO
XXQRX
XMKR
XXXDMZ
CANE
;
run;
data one;;
set one;
if upcase(names) eq : 'X' then names=substr(names,verify(names,'xX'));
put names=;
run;

*or just more explicit and simple;
data one;;
set one;
names=substr(names,verify(names,'xX'));
put names=;
run;

[/pre]


Ksharp Message was edited by: Ksharp

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

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1997 views
  • 0 likes
  • 4 in conversation