BookmarkSubscribeRSS Feed
Sheeba
Lapis Lazuli | Level 10

Hi,

 

I am executing the below step where for each record in dataset1 , all the records in the dataset2 are looped and join criteria is applied and the corresponding data is moved to matched and notmatched. For each record in dataset1 there are more than 80 matches in dataset2 . I am planning to capture only 2 matches . I have initialised a variable dups and increment by 1 for each match.

 

If the value of dup is already 2 , I don’t want further processing for the record in dataset1. Can I stop the  data step iteration for that record and move to the next iteration of the data step. Is there any way i can modify the program to capture only 2 matches.?

 

data matched(index=(seq_num)) notmatched(index=(seq_num));

matchingrecordfound=0;

notmatchingfound=0;

set dataset1;

dups=0;

drop _company matchingrecordfound notmatchingfound dups;

if dups> 2 then

do;

 

/*How do I stop the current iteration of the data step and move to next record in dataset1 */

 

end;

DO i=1 TO xnobs;

SET dataset2 (rename=(company=_company)) NOBS=xnobs POINT=i;

/* steps to process data */

If company=_company then

do;

If abc=xyz and def=kkk then

do;

Dups+1;

Output matched;

End;

Else

do;

output notmatched;

end;

end;

end;

run;

 

 

 

Thanks in advance,

Regards,

Sheeba

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Like this?

 



data MAIN(keep=COMPANY VAR1)
     DUPS(keep=COMPANY VAR2);
  do COMPANY=1 to 20;
    VAR1=COMPANY ;
    if COMPANY ne 3 then output MAIN;
    do VAR2=1 to 80;
      output DUPS;
    end;
  end;
run;

data MATCHED NOTMATCHED;
   merge MAIN (in=M)
         DUPS (in=D);
   by COMPANY;
   if D and ^M then do; 
     output NOTMATCHED; 
     return;
   end;
   if first.COMPANY then COUNT=0;
   COUNT+1;
   if COUNT <= 2 then output MATCHED;
   drop COUNT;
run;

    
Sheeba
Lapis Lazuli | Level 10

Hi ChrisNZ,

Thanks a lot for the reply

Due to nature of the data ( many to many join) I need to go with two set statements..

I have figured out a solution .. I will post after testing ..

Thanks a lot for the suggestion .

Regards,
Sheeba

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 678 views
  • 1 like
  • 2 in conversation