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. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1332 views
  • 2 likes
  • 4 in conversation