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

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
PeterClemmensen
Tourmaline | Level 20

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

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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
sfan6
Calcite | Level 5

Thank you so much! It works!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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