Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7676503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:12:51+00:00 2026-05-31T17:12:51+00:00

I’ve got two tables with similar structure: – First table: id and col1,col2,col3 –

  • 0

I’ve got two tables with similar structure:
– First table: id and col1,col2,col3 – all numerics.
– Second table: id and col4,col5,col6 – all numerics.

I want to remove from the first one all rows which are similar to any of the rows from the second tagble. I consider a row to be similiar to other row when any column from the group col1-col3 is equal to any of the columns from the group col4-col6. Now I’m doing it in 9 consecutive data steps (first checks whether col1=col4, second col1=col5 , …, ninth col3=col6), which probably is not the optimal solution.

Any ideas how to improve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:12:53+00:00Added an answer on May 31, 2026 at 5:12 pm

    This is my solution:

    data vec1;
      set ds2;
      array cvar{*} col4 col5 col6;
      do ijk=1 to dim(cvar);
        compvar=cvar(ijk);
        output;
      end;
    run;
    
    proc sql noprint;
      select distinct compvar into :cvars separated by ' '
      from vec1;
    quit;
    %let numcvar=&sqlobs;
    
    data ds1(drop=i);
      set ds1;
      array myvar(i) col:;
      do over myvar;
        if myvar in (&cvars.) then delete;
      end;
    run;
    

    If you run into trouble with the length of the CVARS macro variable you could use this instead:

    data vec1;
      set ds2;
      array cvar{*} col:;
      do ijk=1 to dim(cvar);
        compvar=cvar(ijk);
        output;
      end;
    run;
    
    proc sort data=vec1 out=vec2(keep=compvar) nodupkey;
      by compvar;
    run;
    
    proc transpose data=vec2 out=flat prefix=x;
    run;
    
    data ds1(keep=id col:);
      set ds1b;
      if _n_=1 then set flat;
      array myvar(i) col:;
      array xvar(j) x:;
      do over myvar;
        do over xvar;
          if myvar=xvar then delete;
        end;
      end;
    run;
    

    The PROC SORT could be eliminated but it makes it more efficient for big data sets.

    Or you could generate a format on the fly:

    data vec1;
      set ds2;
      array cvar{*} col4 col5 col6;
      do ijk=1 to dim(cvar);
        compvar=cvar(ijk);
        output;
      end;
    run;
    
    proc sort data=vec1 out=vec2 nodupkey;
      by compvar;
    run;
    
    data fmt1;
      set vec2;
      length start $20;
      fmtname="remobs";
      start=compress(put(compvar,best.));
      label="remove";
    run;
    
    proc format lib=work cntlin=fmt1;
    run;
    
    data ds1(drop=i);
      set ds1;
      array myvar(i) col:;
      do over myvar;
        if put(myvar,remobs.)="remove" then delete;
      end;
    run;
    

    I suspect this last method would be faster than the two preceding solutions.

    UPDATE

    Using hash objects

    data vec1;
      set ds2;
      array cvar{*} col4 col5 col6;
      do ijk=1 to dim(cvar);
        compvar=cvar(ijk);
        output;
      end;
    run;
    
    proc sort data=vec1 out=vec2 nodupkey;
      by compvar;
    run;
    
    data ds1_new(keep=id col1 col2 col3);
      if _n_ = 0 then set work.vec2;
      declare hash myhash(DATASET:'work.vec2') ; 
      rc=myhash.defineKey('compvar'); 
      myhash.defineDone();
      set ds1;
      array rcarr{*} rc1-rc3;
      array lookup{*} col1 col2 col3;
      do i=1 to dim(lookup);
        rcarr(i)=myhash.find(key: lookup(i));
        if rcarr(i)=0 then delete;
      end;
    run;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.