03-14-2014 04:29 PM
Hello I have an array of procedures of up to 20 cases. I want to loop through looking for specific codes and when found then I don't want to continue looping through. The reason is because the first occurrence of the matching procedure is the one I want to use and there is a possibility another code could match it's not the one I want to evaluate. if ca_dx eq "N" and age>=18 and Adm= "L" then do i = 1 to 20 until (proccde = ''); if ooh ne "Y" and substr(proccde,1,5) in ("1SY80") and substr(proccde,6,2) ne "BA" and atribloc Not In ("0","B") and atribstat ne "A" then ventral_px=1; end; But really for the above I want it to stop at the first procedure that is "1SY80"....is there any way to do this? Thanks.
03-14-2014 04:36 PM
Yes, by a few ways.
1. In your do loop add another condition which is a flag and when the flag is set it stops. Set the flag using a if/then/do when the first occurance is found.
do while (original condition AND flag =0); *Watch your and/ifs
if proccde="ABC" then do;
2. Change the way you search for the instance of procedure code using the whichc/whichn function instead.
03-14-2014 04:52 PM
Hi Reeza Thanks very much. Sorry but I'm not understanding the first section. So using my code, would it be:
do while cco eq "N" and age>=18 and Adm= "L" and flag=0;
if ooh ne "Y" and substr(proccde,1,5) in ("1NT86") and substr(proccde,6,2) ne "BA" and Type="DS" and atribstat ne "A" then do;
There are many others and right now they are all within the do and end piece so is it still okay that I do that I can add the next one after the last line above? Thanks.
03-14-2014 04:56 PM
I'm not 100% sure, depends on your logic
I think you'll have to test it to see.
Essentially the idea is correct, except I think you do have to have the while condition in brackets, and make sure your end statements line up.
03-14-2014 06:07 PM
You could just use the LEAVE statement to exit the loop.
For example try this:
data _null_ ;
do i=1 by 1 until (i>100) ;
if i=10 then leave ;