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;
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
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.
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;
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
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
Very good, LinLin. Why I haven't thought about it.
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?
;
Liked. Art's solution makes PRX solution of mine looks like a chunky hamburger from Macdonald's.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.