mergesasconditional-statementsno-match

sas merge nomatch conditional for only one table


I have 4 tables:

  1. one with a list of users that did sth (post or reply) in march (field email1)
  2. one with replies of users made in jan (several fields but I need to use Mailfrom_Address)
  3. another with replies made in feb (several fields but I need to use Mailfrom_Address)
  4. and another with posting of users for jan, feb and march (this table has email1)

I need to get the users from the table 1 that started doing sth in march. This means that I need to exclude from table 1 the users that are in table 2 or table 3 or table 4 (but only for month jan & feb.. and here's my issue: this condition over table 4).

I started this code.

data lib.all_emails_march_start (keep= email1);
merge lib.all_emails_march (IN=In1) 
lib.replies_ene_2 (rename= (Mailfrom_Address=email1)) (IN=In2)
lib.replies_feb_2 (rename= (Mailfrom_Address=email1)) (IN=In3)
lib.listings_5 where anomes in ('2014-01', '2014-02') (IN=In4);
by email1;
if (In1=1 and In2=0 and In3=0 and In4=0) then output lib.all_emails_march_start;
run;

but the condition should be only for the table 4 (listings_5) and this variable (anomes) isn't in the other tables (1 to 3), so I don't know how to do this.

I would like to do this in only one stp, and not create first a table for listings with only jan and feb. Would you please give me some ideas?

Thanks!!!! :D :D :D


Solution

  • PROC SQL is probably more suited to this...

    proc sql ;
      create table lib.all_emails_march_start as
      select *
      from lib.all_emails_march 
      where user not in(select distinct user from lib.replies_ene_2)
        and user not in(select distinct user from lib.replies_feb_2)
        and user not in(select distinct user from lib.listings_5 
                        where anomes in ('2014-01', '2014-02'))
      ;
    quit ;