BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5

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;

8 REPLIES 8
Haikuo
Onyx | Level 15

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

R_Win
Calcite | Level 5

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.

Linlin
Lapis Lazuli | Level 10

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;

Haikuo
Onyx | Level 15

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

Linlin
Lapis Lazuli | Level 10

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

Haikuo
Onyx | Level 15

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

art297
Opal | Level 21

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?

;

Haikuo
Onyx | Level 15

Liked. Art's solution makes PRX solution of mine looks like a chunky hamburger from Macdonald's. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 8 replies
  • 2233 views
  • 2 likes
  • 4 in conversation