It looks like it is as you said a problem with invalid data.
I ran your array but I has the same effect, but I found an important bit in the log:
dat_ops95= dat_ops96= dat_ops97= dat_ops98= dat_ops99= dat_ops100= i=101 _ERROR_=1 _N_=1
NOTE: Ungültiges zweites Argument für Funktion SUBSTR in Zeile 2371 Spalte 14. --> translated: Invalid second argument for the function substr
NOTE: Over 100 NOTES, additional NOTES suppressed.
NOTE: Ungültiges zweites Argument für Funktion SUBSTR in Zeile 2371 Spalte 14. --> translated: Invalid second argument for the function substr
The data look like this, for the variables ops_ko1 till ops_ko100 and fromatted as $CHAR19. :
1234b8:r:20060607
627::20071012
382027:l:20071212
182b::20071615
17293b:r:20081281
Thank you very much!
The error shows you the problem:
dat_ops95= dat_ops96= dat_ops97= dat_ops98= dat_ops99= dat_ops100= i=101 _ERROR_=1 _N_=1
There is not data in dat_ops95, or 96 etc. Therefore any substr() evaluation will fail as lengthn(string)=0 then -7 = -7, invalid for substr().
Again, post test data exactly as you have it, as a datastep. Follow this post:
It is impossible for me to cover data that you have if I don't know about it (i.e. you post on one column, there is 100 in the log).
Put an if around the calculation;
data test1; set test; array ops_ko ops_ko1-ops_ko100; array dat_ops dat_ops1-dat_ops100; do i=1 to 100; if lengthn(ops_ko{i}) > 0 then do; dat_ops{i}=substr(ops_ko{i},lengthn(ops_ko{i})-7,10); ops_ko{i}=tranwrd(ops_ko{i},strip(dat_ops{i}),""); end; end; run;
Great, thank you! It is working just fine.
I will read your link for the next time and will post proper test data.
What is the rule that excludes data from the row with 627::20071012?
data test;
input @1 var $17. @18 var1 $20.;
cards;
1234b8:r:20060607 1234b8:r:20060607
152::20071012 627:r:20091012
382027:l:20071212 382027::20051212
182b::20070615 182b::20010615
17293b:r:20081231 17293b:r:20001231
;run;
DATA test1;
format date date1 yymmdd10.;
set test;
array vr (*) $ var var1;
array cd (*) $ code code1;
array dt(*) $ date date1;
array pr (*) $ prt1 prt2;
do i=1 to dim(vr);
if _N_=1 then RE = PRXPARSE("/\:\d{8}/"); RX=PRXPARSE("/\d+\:{2}\d{8}/");
retain RE RX;
if prxmatch(RX, vr(i)) = 0 then do;
call PRXSUBSTR(RE,vr(i),START,LENGTH);
if START GT 0 then do;
cd{i} = SUBSTRN(vr{i},START + 1,LENGTH - 1);
dt(i) =input (cd(i),yymmdd10.);
pr(i)=SUBSTRN(vr(i),1,LENGTH(vr(i)) - LENGTH);
end;
end;
end;
drop i Start Length RE RX;
run;
Hi mansour_ibrahim,
thank you for the code! But now it exclusively cuts the data with an l or r in between.
This one in the code fo RW9:
dat_ops{i}=substr(ops_ko{i},lengthn(ops_ko{i})-7,10);
And for mansour_ibrhaim:
if _N_=1 then RE = PRXPARSE("/\:\d{8}/"); RX=PRXPARSE("/\d+\:{2}\d{8}/");
retain RE RX;
if prxmatch(RX, ops_ko(i)) = 0 then do;
call PRXSUBSTR(RE,ops_ko(i),START,LENGTH);
if START GT 0 then do;
cd{i} = SUBSTRN(ops_ko{i},START + 1,LENGTH - 1);
dt(i) =input (cd(i),yymmdd10.);
pr(i)=SUBSTRN(ops_ko(i),1,LENGTH(ops_ko(i)) - LENGTH);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.