data have; input x $80.; length Bacode $ 20; n+1; pid=prxparse('/atmbarcode:"\w+/i'); s=1; e=length(x); call prxnext(pid,s,e,x,p,l); do while(p>0); Bacode=substr(x,p,l); output; call prxnext(pid,s,e,x,p,l); end; keep n x Bacode ; cards; atmbarcode:"FE235. atmbarcode:"Yu23 ; run; proc transpose data=have out=want(drop=_name_) prefix=Bacode; by n x; var Bacode; run;
If you would like to convert each row into multiple rows, that is up to you. Here's a solution that reads multiple entries from the same row:
data want;
infile rawdata;
input @;
length SA_string $ 20;
do i=1 to countw(_infile_, '.');
SA_string = scan(_infile_, 3*i, '"');
output;
end;
run;
There might be some tweaking needed, since you haven't shown what the data looks like when there are multiple entries per row. Who knows? Maybe my imagination is correct.
Are your records always in pairs, or you're always using the second one? What's your delimiter in the second row, it doesn't look like there's any.
You need to explain all the rules.
Here's the documentation that shows what the SCAN function can do:
Does the Barcode always like AZ98989 ?
data have;
input x $80.;
length Bacode $ 20;
n+1;
pid=prxparse('/az\d+/i');
s=1;
e=length(x);
call prxnext(pid,s,e,x,p,l);
do while(p>0);
Bacode=substr(x,p,l);
output;
call prxnext(pid,s,e,x,p,l);
end;
keep n x Bacode ;
cards;
Qw. Bar Az011. ABC. BarAz345. Wer.BarAz056.
Tr. BrAz078. Dfg. . Braz078. Tyr.
Ee. Br Az089. Rty
;
run;
proc transpose data=have out=want(drop=_name_) prefix=Bacode;
by n x;
var Bacode;
run;
"I have a table that has 100 col that start with Barcode barvode1 and Barcode3 .... in your code I was able to get data when I refer the col name Barcode3 for example .."
If you have multiple variables, you can combine them all together into one variable , like the following code:
data have;
input x $80.;
length Bacode $ 2000;
Bacode=catx(' ',of Bacode1-Bacode100);
...........
data have; input x $80.; length Bacode $ 20; n+1; pid=prxparse('/atmbarcode:"\w+/i'); s=1; e=length(x); call prxnext(pid,s,e,x,p,l); do while(p>0); Bacode=substr(x,p,l); output; call prxnext(pid,s,e,x,p,l); end; keep n x Bacode ; cards; atmbarcode:"FE235. atmbarcode:"Yu23 ; run; proc transpose data=have out=want(drop=_name_) prefix=Bacode; by n x; var Bacode; run;
There are too many pattern you to consider about . Without see all your data , it is hard to write corrrect PRX .
data have;
input x $80.;
length Bacode $ 20;
n+1;
pid=prxparse('/atmbarcode:\W*\w+/i');
s=1;
e=length(x);
call prxnext(pid,s,e,x,p,l);
do while(p>0);
Bacode=substr(x,p,l);
output;
call prxnext(pid,s,e,x,p,l);
end;
keep n x Bacode ;
cards;
atmbarcode:"FE235. atmbarcode:"Yu23
Atmbarcode:TU35. Row#% atmbarcode:WE45
;
run;
proc transpose data=have out=want(drop=_name_) prefix=Bacode;
by n x;
var Bacode;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.