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

Hello, 

 

@Tom wrote the following code so that I could see how my MERGE statement had more than one data set with repeats of BY values:

 

*MERGE statement has more than one data set with repeats of BY values;
proc sort data=paper.CSRP_annual_returns
               out=paper.CSRP_annual_returns2
               nodupkey;
  by ticker;
run;

*Merge CEO data and firm data; 
DATA paper.ceo_firm ;
   length ticker $5 source $10;
  MERGE
    paper.CSRP_annual_returns2 (in=in1)
    paper.compustat_execucomp4 (in=in2)
  ;
  BY ticker;
  if in1 and in2 then source='BOTH';
  else if in1 then source='ANNUAL';
  else source='EXECCOMP';
RUN;

The output includes a variable that tells me which of the two data sets the observation is coming from. It also says which are coming from both. I would like to keep only those rows which have "BOTH" as a source. What is the best way to do this? 

 

Here is an example of what the current output looks like:

 

rowtickersource      .     .      ........
408ACOBOTH20109.0442006703Lawrence E. Washow 1000 7456AMCOL INTERNATIONAL CORPChief Executive Officer, President, Director and Member of Executive CommitteeCEO67000413.76136666.6283163.885050.2686705050.2685547.3361498.6994190.768211.9880.676
409ACOBOTH20119.0442006703Ryan F. McKendrick 1000 22282AMCOL INTERNATIONAL CORPChief Executive Officer, President and DirectorCEO5000613.2342.6601.786363.20335.6442456.4335001843.2332609.9981040.8183000201.9490.632
410ACOBOTH20129.0442006703Ryan F. McKendrick 1000 22282AMCOL INTERNATIONAL CORPChief Executive Officer, President and DirectorCEO52500370.8496653.5436.0112081.3515252081.3511909.2281090.818315090.3570.279
411ACOBOTH20139.0442006703Ryan F. McKendrick 1000 22282AMCOL INTERNATIONAL CORPChief Executive Officer, President, Director and Member of Executive CommitteeCEO700517833.472508.3750420.20437.6153016.66612173016.6661877.9321436.183420075.0840.231
412ACOMANNUAL201088.344227811     .     .      ........
413ACORBOTH20107.2911181633Ron Cohen, M.D. 1000 46385ACORDA THERAPEUTICS INCFounder, Chairman, Chief Executive Officer and PresidentCEO589.75592.863817.3444549.547007.359556.8511182.619557.2985485.4619276.5029276.5021149.8372.941
414ACORBOTH20117.2911181633Ron Cohen, M.D. 1000 46385ACORDA THERAPEUTICS INCFounder, Chief Executive Officer, President and DirectorCEO6350965.1251605.196557.9207.353770.5916353770.5835966.9269085.9899911.1291164.3592.904
415ACORBOTH20127.2911181633Ron Cohen, M.D. 1000 46385ACORDA THERAPEUTICS INCFounder, Chief Executive Officer, President and DirectorCEO6900988.1251590.684571.207.353847.3596903847.4252598.8728466.1859028.2651309.413.251
416ACORBOTH20137.2911181633Ron Cohen, M.D. 1000 46385ACORDA THERAPEUTICS INCFounder, Chief Executive Officer, President and DirectorCEO720.8330685.351976.389527.807.653918.022720.8333918.02212601.7197101.2157681.2151300.2663.115
417ACORBOTH20147.2911181633Ron Cohen, M.D. 1000 46385ACORDA THERAPEUTICS INCFounder, Chief Executive Officer, President and DirectorCEO745.8330700.4131939.685651.607.654045.181745.8334045.1813887.2886710.9387310.9381389.8883.244
418ACORBOTH20157.2911181633Ron Cohen, M.D. 1000 46385ACORDA THERAPEUTICS INCFounder, Chief Executive Officer, President and DirectorCEO768.750607.581510.794553.72807.953448.802768.753448.8024685.34912235.27412853.2741236.7612.68
419ACORBOTH20167.2911181633Ron Cohen, M.D. 1000 46385ACORDA THERAPEUTICS INCFounder, Chief Executive Officer, President and DirectorCEO772.501046.5011043.884562.3807.953433.215772.53433.2152660.4723136.163818.4321422.283.065
420ACPWANNUAL201094.858409388     .     .      ........
421ACREANNUAL20120.7119757952

 

And here is the log:

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
70
71 *MERGE statement has more than one data set with repeats of BY values;
72 proc sort data=paper.CSRP_annual_returns
73 out=paper.CSRP_annual_returns2
74 nodupkey;
75 by ticker;
76 run;
 
NOTE: There were 53176 observations read from the data set PAPER.CSRP_ANNUAL_RETURNS.
NOTE: 42661 observations with duplicate key values were deleted.
NOTE: The data set PAPER.CSRP_ANNUAL_RETURNS2 has 10515 observations and 3 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.03 seconds
user cpu time 0.01 seconds
system cpu time 0.01 seconds
memory 6126.06k
OS Memory 36452.00k
Timestamp 04/01/2018 07:47:46 PM
Step Count 61 Switch Count 2
Page Faults 0
Page Reclaims 876
Page Swaps 0
Voluntary Context Switches 46
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 528
 
 
77
78 *Merge CEO data and firm data;
79 DATA paper.ceo_firm ;
80 length ticker $5 source $10;
81 MERGE
82 paper.CSRP_annual_returns2 (in=in1)
83 paper.compustat_execucomp4 (in=in2)
84 ;
85 BY ticker;
86 if in1 and in2 then source='BOTH';
87 else if in1 then source='ANNUAL';
88 else source='EXECCOMP';
89 RUN;
 
NOTE: There were 10515 observations read from the data set PAPER.CSRP_ANNUAL_RETURNS2.
NOTE: There were 13346 observations read from the data set PAPER.COMPUSTAT_EXECUCOMP4.
NOTE: The data set PAPER.CEO_FIRM has 21807 observations and 109 variables.
NOTE: DATA statement used (Total process time):
real time 0.17 seconds
user cpu time 0.02 seconds
system cpu time 0.05 seconds
memory 4222.00k
OS Memory 35504.00k
Timestamp 04/01/2018 07:47:47 PM
Step Count 62 Switch Count 2
Page Faults 0
Page Reclaims 738
Page Swaps 0
Voluntary Context Switches 1472
Involuntary Context Switches 1
Block Input Operations 544
Block Output Operations 88840
 
 
90
91 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
103
 
 
Thanks for the help!
1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You can do that by modifying @Tom's code:

*Merge CEO data and firm data; 
DATA paper.ceo_firm ;
   length ticker $5 source $10;
  MERGE
    paper.CSRP_annual_returns2 (in=in1)
    paper.compustat_execucomp4 (in=in2)
  ;
  BY ticker;
  if in1 and in2;
RUN;

Art, CEO, AnalystFinder.com

 

 

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

You can do that by modifying @Tom's code:

*Merge CEO data and firm data; 
DATA paper.ceo_firm ;
   length ticker $5 source $10;
  MERGE
    paper.CSRP_annual_returns2 (in=in1)
    paper.compustat_execucomp4 (in=in2)
  ;
  BY ticker;
  if in1 and in2;
RUN;

Art, CEO, AnalystFinder.com

 

 

sastuck
Pyrite | Level 9

perfect. Thanks!

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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