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

## how to create an opposite set in SAS?

Hello everyone, I have data set A that contains the following obs. The whole data set contain variables from 2013 to 2018. I need to create a new data set B that is the opposite data set of A. For company 0, I need to find the years that didn't send earnings announcements (year 2013, 2017). For company 1, the obs in data set B is year 2013, 2014, 2018. How could I use SAS to find the opposite data set? I very appreciate your help.

company ID        earnings'annoucement        announcement date

0                                         2.4                                 4/10/2014

0                                         3.7                                  5/2/2015

0                                         4.3                                   3/8/2016

0                                         -1.0                                  2/5/2018

1                                        9.2                                   3/5/2015

1                                        8.3                                    6/2/2016

1                                        7.3                                   7/4/2017

2                                        4.2                                   3/6/2014

2                                        3.7                                   2/14/2018

1 ACCEPTED SOLUTION

Accepted Solutions
Tourmaline | Level 20

## Re: how to create an opposite set in SAS?

Here is one way

``````data a;
input companyID eannoucement announcementdate :mmddyy10.;
format announcementdate mmddyy10.;
datalines;
0 2.4 4/10/2014
0 3.7 5/2/2015
0 4.3 3/8/2016
0 -1.0 2/5/2018
1 9.2 3/5/2015
1 8.3 6/2/2016
1 7.3 7/4/2017
2 4.2 3/6/2014
2 3.7 2/14/2018
;

data b(keep=companyID year);
array y{2013:2018} _temporary_ (6*0);
do until (last.companyID);
set a;
by companyID;
y[year(announcementdate)]=1;
end;
do year=2013 to 2018;
if y[year]=0 then output;
end;
call stdize('replace','mult=',0,of y[*],_iorc_);
run;
``````

Result:

```companyID Year
0	2013
0	2017
1	2013
1	2014
1	2018
2	2013
2	2015
2	2016
2	2017```
2 REPLIES 2
Tourmaline | Level 20

## Re: how to create an opposite set in SAS?

Here is one way

``````data a;
input companyID eannoucement announcementdate :mmddyy10.;
format announcementdate mmddyy10.;
datalines;
0 2.4 4/10/2014
0 3.7 5/2/2015
0 4.3 3/8/2016
0 -1.0 2/5/2018
1 9.2 3/5/2015
1 8.3 6/2/2016
1 7.3 7/4/2017
2 4.2 3/6/2014
2 3.7 2/14/2018
;

data b(keep=companyID year);
array y{2013:2018} _temporary_ (6*0);
do until (last.companyID);
set a;
by companyID;
y[year(announcementdate)]=1;
end;
do year=2013 to 2018;
if y[year]=0 then output;
end;
call stdize('replace','mult=',0,of y[*],_iorc_);
run;
``````

Result:

```companyID Year
0	2013
0	2017
1	2013
1	2014
1	2018
2	2013
2	2015
2	2016
2	2017```
Calcite | Level 5

## Re: how to create an opposite set in SAS?

Thank you so much! It works!

Discussion stats
• 2 replies
• 460 views
• 0 likes
• 2 in conversation