## Find Dlm Postion

Regular Contributor
Posts: 229

# Find Dlm Postion

I wnat to find the 7 th positon of delimter '?'  as (i am having 120 delimiters in a line  as i have given below as example) data a; input id\$ 1-10; i=findc(id,'?'); do until i=32; cards; 1?2?3445??6?7?8?9?10 ; run;

Posts: 3,167

## Re: Find Dlm Postion

You probably need to use PRX;

data a;

input id\$20.;

cards;

1?2?3445??6?7?8?9?10

; run;

data want (keep=position);

set a;

start=1;

if _n_=1 then

pattern=prxparse("/\?/");

do _n_=1 to 7;

call prxnext(pattern,start,-1,id,position,len);

end;

run;

proc print;run;

Haikuo

Regular Contributor
Posts: 229

## Re: Find Dlm Postion

actually my DLM was '^' but when i changed it pattern=prxparse("/\^/"); iam getting warnings ERROR: Argument 1 to the function PRXNEXT must be a positive integer returned by PRXPARSE for a vali d pattern.

Super Contributor
Posts: 1,636

## Re: Find Dlm Postion

options nocenter;

data a;

id="1^2^3445^^6^7^8^9^10";

output;

id="^^^^^^^";

output;

run;

data want(keep=id position);

set a;position=0;

start= 1;

do n=1 to 7;

i=findc(substr(id,start),'^');

position+i;

start+i;

end;

run;

proc print;run;

Posts: 3,167

## Re: Find Dlm Postion

That is odd. it works for me:

data a;

input id\$20.;

cards;

1^2^3445^^6^7^8^9^10

; run;

data want (keep=position);

set a;

start=1;

if _n_=1 then

pattern=prxparse("/\^/");

do _n_=1 to 7;

call prxnext(pattern,start,-1,id,position,len);

end;

run;

Obs position

1 16

What version of SAS you are using, on what platform?

Haikuo

Super Contributor
Posts: 1,636

## Re: Find Dlm Postion

another approach:

options nocenter;

data a;

id="1?2?3445??6?7?8?9?10";

output;

id="???????";

output;

run;

data want(keep=id position);

set a;position=0;

start= 1;

do n=1 to 7;

i=findc(substr(id,start),'?');

position+i;

start+i;

end;

run;

proc print;run;

Obs    id                      position

1     1?2?3445??6?7?8?9?10       16

2     ???????                     7

Message was edited by: Linlin

Posts: 3,167

## Re: Find Dlm Postion

Very good, LinLin. Why I haven't thought about it.

PROC Star
Posts: 8,164

## Re: Find Dlm Postion

Here is another alternative:

data a;

informat id \$30.;

input id;

CALL SCAN(id, 7, i, l,'?','M');

i=i+l;

cards;

1?2?3445??6?7??8??9?10?

;