BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
div44
Calcite | Level 5

data test888;
set test88;
array gap(*) gap1-gap370;
do r=1 to 370;
do y=1 to 370;
if ((gap(y) - gap(r)) >= 90) then leave;
end;
end;
run;

 

I cannot get the code to work. 

I want to find the combination of gap(R) and gap(y) which have a difference of more than 89.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

 

data HAVE;
  array GAP(*) GAP1-GAP370;
  do I=1 to 370;
    GAP[I]=ranuni(0)*100;
  end;
run;

data WANT;
  keep I J VAL_I VAL_J;
  set HAVE;
  array GAP(*) GAP1-GAP370;
  do I=1 to 369;
    do J=I+1 to 370;
      if abs(GAP[I]-GAP[J]) >= 90 then do;
        VAL_I=GAP[I];
        VAL_J=GAP[J];
        output;
      end;
    end;
  end;
run;

 

 

View solution in original post

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Like this?

 

data HAVE;
  array GAP(*) GAP1-GAP370;
  do I=1 to 370;
    GAP[I]=ranuni(0)*100;
  end;
run;

data WANT;
  keep I J VAL_I VAL_J;
  set HAVE;
  array GAP(*) GAP1-GAP370;
  do I=1 to 369;
    do J=I+1 to 370;
      if abs(GAP[I]-GAP[J]) >= 90 then do;
        VAL_I=GAP[I];
        VAL_J=GAP[J];
        output;
      end;
    end;
  end;
run;

 

 

div44
Calcite | Level 5
Thank you so much for your help !!
Astounding
PROC Star

Chris has the right idea, changing the limits on your loops.  The program will run faster if you don't check the combinations that you don't need to check.

 

Your original program is probably encountering this issue.  (I can't test it right now.)  The LEAVE statement only applies to a single loop.  So it gets you out of the interior loop, without getting you out of the exterior loop.  Just take that entire statement and repeat it after the first END statement.

div44
Calcite | Level 5
Thank you so much for your help

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
  • 4 replies
  • 1125 views
  • 1 like
  • 3 in conversation