BookmarkSubscribeRSS Feed
Shmuel
Garnet | Level 18

The next code is probably my typo:

/* DELETE TEMPORARY DATASETS */
proc datasets lib=paper; delete ceo_firm_1 ceo_firm_2 nolist; quit;

it should be:

/* DELETE TEMPORARY DATASETS */
proc datasets lib=paper NOLIST; delete ceo_firm_1 ceo_firm_2 ; quit;

if you run that code and the datasets are already removed - you will get appropriate message.

Feel free to run it.

 

 

The same with next code - corrected:

/* CHECK FOR DUPLICATES */
data is_dup;
 set paper.CSRP_Monthly_Stock_char4;    /* dataset origin containing var to add VOL ? */
  by ticker year;
     if not (first.year and last.year);
run;

Are there duplicates ? If positive check what are the differences between the observations of the same TICKER and YEAR values.

Have you used the SORT NODUPKEY or added another key variable to the sql join conditions?

 

In case final data answers to your request, please assign the post as solution.

 

 

sastuck
Pyrite | Level 9

Hey,

 

I ran into further errors even after implementing your revisions. For fear of getting lost in the code (my results are due relatively soon), I have copy-and-pasted my original code back into my program. If you would like to know what the errors were, let me know and I can go back and try to retrieve the log for you. Otherwise, thanks so much for trying to help me get through this issue. I may post a question in on the board relating to the original code you offered me. Feel free to partake in that conversation. Thanks again, and sorry I didn't have the time to work with you to figure this one out.

Shmuel
Garnet | Level 18

I asked you to check for duplicates by running:

/* CHECK FOR DUPLICATES */
data is_dup;
 set paper.CSRP_Monthly_Stock_char4;    /* dataset origin containing var to add VOL ? */
  by ticker year;
     if not (first.year and last.year);
run;

Please post  - upto 10 obs - from the result: is_dup dataset, unless the dataset is empty.

 

You have not answered my question - are there duplicates ?

 

 

 

sastuck
Pyrite | Level 9

Here are the results from the code you posted:

 

rowtickerdate         year
2A2010-02-262010 
3A2010-03-312010 
4A2010-04-302010 
5A2010-05-282010 
6A2010-06-302010 
7A2010-07-302010 
8A2010-08-312010 
9A2010-09-302010 
10A2010-10-292010 
11A2010-11-302010 
12A2010-12-312010 
13A2011-01-312011 
14A2011-02-282011 
15A2011-03-312011 
16A2011-04-292011 
17A2011-05-312011 
18A2011-06-302011 
19A2011-07-292011 
20A2011-08-312011

 

and according to this code:

 

*find duplicates: ticker/year combo;
proc freq data=paper.CSRP_Monthly_Stock_char4;
	tables ticker * year / noprint 
		out=paper.multiple_tyCSRP (where=(count > 1));
run;

there are duplicates. This is a snapshot of the output:

 

rowtickeryearcountpercent
2A2011120.00198938 
3A2012120.00198938 
4A2013120.00198938 
5A2014120.00198938 
6A2015120.00198938 
7A2016120.00198938 
8A2017120.00198938 
9AA2010120.00198938 
10AA2011120.00198938 
11AA2012120.00198938 
12AA2013120.00198938 
13AA2014120.00198938 
14AA2015120.00198938 
15AA2016110.0018235984 
16AA2017120.00198938 
17AAAP2016120.00198938 
18AAAP2017120.00198938 
19AABA201760.00099469
Shmuel
Garnet | Level 18

As much as I see the key variables to get distinct values (I used previously the term unique)

are:   ROW TICKER YEAR which means that the code to bring the new variable should be:

 

*bring variable in from other data set; 
proc sql;
     create table want as 
      select  a.* , b.VOL
      from paper.ceo_firm as a
      left join paper.CSRP_Monthly_Stock_char4 as b
     on a.ROW = b.ROW and      /* <<< line added <<< */
          a.ticker = b.ticker and
          a.year = b.year;
quit;
sastuck
Pyrite | Level 9

Thanks. Here's the new log:

 

 Errors (4)
 Warnings
 Notes (3)
 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 70         
 71         *bring variable in from other data set;
 72         proc sql;
 73              create table want as
 74               select  a.* , b.VOL
 75               from paper.ceo_firm as a
 76               left join paper.CSRP_Monthly_Stock_char4 as b
 77              on a.ROW = b.ROW and
 78                   a.ticker = b.ticker and
 79                   a.year = b.year;
 ERROR: Column ROW could not be found in the table/view identified with the correlation name A.
 ERROR: Column ROW could not be found in the table/view identified with the correlation name A.
 ERROR: Column ROW could not be found in the table/view identified with the correlation name B.
 ERROR: Column ROW could not be found in the table/view identified with the correlation name B.
 NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
 80         quit;
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              8604.56k
       OS Memory           36272.00k
       Timestamp           04/15/2018 01:19:36 PM
       Step Count                        40  Switch Count  0
       Page Faults                       0
       Page Reclaims                     532
       Page Swaps                        0
       Voluntary Context Switches        8
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           0
       
 81         
 82         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 94  
sastuck
Pyrite | Level 9

@SASKiwi helped me out, by the way. In case you're curious, here's the code he came up with:

 

proc sql;
     create table ceo_firm as 
      select  a.* , b.VOL
      from paper.ceo_firm as a
      left join
     (select ticker
                ,year
                ,sum(VOL) as VOL
      from paper.CSRP_Monthly_Stock_char4
      group by ticker
              ,year
     ) as b
     on a.ticker = b.ticker and
     a.year = b.year;
quit;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 21 replies
  • 3275 views
  • 5 likes
  • 2 in conversation