Poschar for multiple variable

Discussions about editing and cleaning data
Forum rules
New release: CSPro 8.0
Post Reply
Ronin

Poschar for multiple variable

Post by Ronin »

Hi all,

i have a multiple alpha variable with string "ABCDEFGHIJWZ". i need to convert them to numbers 1,2,3 .....
So A = 1, B = 2 etc.

I used poschar function. Its ok unltil a variable as two ore more characters ,

So if x = AB E then poschar returns me only the first, so 1 in clone field.

How can i set to returns me all , in this case 1 at clone 1, 2 at clone 2 etc ?????
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Poschar for multiple variable

Post by Gregory Martin »

See attached for a sample application that demonstrates how to do this. It's a little trickier than necessary because I made it a data entry application where you can see the results for yourself.

But the idea here is that you loop through each character of your alpha variable and then search for it in a string that includes all possibilities.
PROC GLOBAL

alpha (26) alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


PROC MULTPOS_FF

preproc

    
set behavior() canenter(notappl) on(noconfirm);


PROC NUMBERS

preproc

    
if curocc() <= length(strip(MULTALPH)) then
        NUMBERS =
poschar(MULTALPH[curocc():1],alphabet);

    
else
        NUMBERS =
notappl;

    
endif;

    
noinput;
Attachments
multpos.zip
(2.63 KiB) Downloaded 599 times
Post Reply