Dear altruists,
I have the following SAS datasets:
data data1;
input Company_ID$ Fiscal_Year Fiscal_Quarter Announcement : yymmdd10.;
format Announcement yymmdd10.;
cards;
1001 2001 2 2001-08-31
1001 2001 3 2001-11-30
2002 2001 3 2001-07-31
2002 2001 4 2001-10-31
2002 2002 1 2002-01-31
3003 2001 4 2001-10-31
3003 2002 1 2002-01-31
4004 2004 4 2004-12-31
4004 2005 1 2005-04-02
5005 2001 1 2001-01-31
;
run;
data data2;
input Company_ID$ Company_Name$ Year_End_Month$;
cards;
2002 Google December
3003 Amazon June
5005 Apple March
;
run;
I want to keep only those observations in data1 that matches data2.
However, when matching the observations, I also want to include the additional columns that are in data2.
Essentially, I am looking for the following output:
Company_ID |
Fiscal_Year |
Fiscal_Quarter |
Announcement |
Company_Name |
Year_End_Month |
2002 |
2001 |
3 |
2001-07-31 |
Google |
December |
2002 |
2001 |
4 |
2001-10-31 |
Google |
December |
2002 |
2002 |
1 |
2002-01-31 |
Google |
December |
3003 |
2001 |
4 |
2001-10-31 |
Amazon |
June |
3003 |
2002 |
1 |
2002-01-31 |
Amazon |
June |
5005 |
2001 |
1 |
2001-01-31 |
Apple |
March |
I have tried the following code, but it does not seem to work:
proc sort data=work.data1;
by Company_ID;
run;
proc sort data=work.data2;
by Company_ID;
run;
data work.filtered_data;
merge work.data1 (in=a) work.data2 (in=b);
by Company_ID;
if b and not a;
run;
(Edit: changed the code a bit, but still does not show any result)
Requesting your kind support 🙂