<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: merging compustat global annual data and compusat global security daily data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332140#M271999</link>
    <description>&lt;P&gt;Your "want" dataset has 7.8M records, but&amp;nbsp; the security dataset had 8.6M.&amp;nbsp; That means there are .8M security records for which there were no matching annual records.&amp;nbsp; I presume that is unsurprising, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does your other annual data look like? Does it have gvkey? You mention fyear (fiscal year).&amp;nbsp; Are you saying that your other annual data does not have datadate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you think that sorting by fyear is neccessary? If your current data is sorted by&amp;nbsp;gvkey / datadate, is it not likely to also already be sorted by gvkey/fiscal year?&amp;nbsp; You can test this by this simple step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set want ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by gvkey fyear;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If SAS produces no "out of order" message on the log for this program, you have demonstrated that the data is already sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also maybe you should have merged all the annual records first (smaller N), then merge with the daily data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: For latecomers to this topic, here's the link to the code that answered the topic question:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331967#M43407" target="_self"&gt;https://communities.sas.com/t5/General-SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331967#M43407&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2017 14:51:38 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-02-13T14:51:38Z</dc:date>
    <item>
      <title>merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331929#M271986</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to merge compustat global annual data with compustat&amp;nbsp;global security data by gvkey. The codes I have used so far don't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your assistance would be very much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 05:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331929#M271986</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-02-12T05:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331932#M271987</link>
      <description>&lt;P&gt;Did the suggestions you got in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Data-Step-Merge-variable-declared-as-both-character-and-numeric/m-p/331776#M43373" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/Data-Step-Merge-variable-declared-as-both-character-and-numeric/m-p/331776#M43373&lt;/A&gt;&amp;nbsp;not bring you on the right track?&lt;/P&gt;
&lt;P&gt;Please post the code you tried, the log, how the result differed from your expectations, and some example data (if data is retrieved from the internet, post the URL).&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 07:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331932#M271987</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-12T07:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331936#M271988</link>
      <description>&lt;P&gt;As I indicated, I used the wrong identifier so I did check my data and did the right thing thanks to you guys.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On this issue, I have actually succeeded in merging them but I'm not sure if it is correct. I used these codes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;proc sort data=data1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by gvkey;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;proc sort data=data2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by gvkey;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;data data3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge data1(in=a) data2(in=b);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by gvkey;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if b;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 08:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331936#M271988</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-02-12T08:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331937#M271989</link>
      <description>&lt;P&gt;First of all, take a look at the log. There should be no WARNINGs or ERRORs. The NOTEs should only be of the nature "xxx records read from ..." and "the dataset .... has xxxx records and yyy variables".&lt;/P&gt;
&lt;P&gt;Crucial for a datastep merge is the relationship between the datasets. It should be 1:1 or 1:n, m:n are probably handled better with SQL.&lt;/P&gt;
&lt;P&gt;So if you have any doubts, post the log.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 09:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331937#M271989</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-12T09:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331938#M271990</link>
      <description>&lt;P&gt;If both data1 and data2 have same gvkey more than once ( relation n:m where n&amp;gt;1 and m&amp;gt;1)&lt;/P&gt;
&lt;P&gt;you may have issues with the merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If in any of the two datas each gvkey occures once only it will work perfectly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In Case of N:M relation better do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     create table want as select *
     from data1 as a
     join data2 as b
     on a.gvkey = b.gvkey;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In case not all keys in data1 exsist in data2 or vice-versa then you may need&lt;/P&gt;
&lt;P&gt;use inner join or full join.&lt;/P&gt;
&lt;P&gt;See next PDF documentation:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.google.co.il/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0ahUKEwiMkqTum4rSAhWIWxQKHWsdBlIQFgghMAA&amp;amp;url=http%3A%2F%2Fsupport.sas.com%2Fresources%2Fpapers%2Fproceedings12%2F251-2012.pdf&amp;amp;usg=AFQjCNGX8KcGrMc9fSQ3s55p0Rnto60jnw&amp;amp;sig2=XBymq26ZUt-F2389C0J9dQ&amp;amp;bvm=bv.146786187,d.bGs&amp;amp;cad=rja" target="_self"&gt;https://www.google.co.il/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0ahUKEwiMkqTum4rSAhWIWxQKHWsdBlIQFgghMAA&amp;amp;url=http%3A%2F%2Fsupport.sas.com%2Fresources%2Fpapers%2Fproceedings12%2F251-2012.pdf&amp;amp;usg=AFQjCNGX8KcGrMc9fSQ3s55p0Rnto60jnw&amp;amp;sig2=XBymq26ZUt-F2389C0J9dQ&amp;amp;bvm=bv.146786187,d.bGs&amp;amp;cad=rja&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 09:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331938#M271990</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-12T09:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331941#M271991</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm posting the log here; i got no error per se. Please ignore the data set definitions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My next challenge is to calculate some variables at the end of the year fiscal year. My question is how to set the date right.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;13&amp;nbsp;&amp;nbsp; proc sort data=theo.to_be_merged;&lt;/P&gt;&lt;P&gt;14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by gvkey;&lt;/P&gt;&lt;P&gt;15&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Input data set is already sorted, no sorting done.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;16&amp;nbsp;&amp;nbsp; proc sort data=theo.security_daily;&lt;/P&gt;&lt;P&gt;17&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by gvkey;&lt;/P&gt;&lt;P&gt;18&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Input data set is already sorted, no sorting done.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;19&amp;nbsp;&amp;nbsp; data data3;&lt;/P&gt;&lt;P&gt;20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge theo.to_be_merged(in=a) theo.security_daily(in=b);&lt;/P&gt;&lt;P&gt;21&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by gvkey;&lt;/P&gt;&lt;P&gt;22&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if b;&lt;/P&gt;&lt;P&gt;23&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: MERGE statement has more than one data set with repeats of BY values.&lt;/P&gt;&lt;P&gt;NOTE: There were 2357018 observations read from the data set THEO.TO_BE_MERGED.&lt;/P&gt;&lt;P&gt;NOTE: There were 86856448 observations read from the data set THEO.SECURITY_DAILY.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.DATA3 has 86857588 observations and 38 variables.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7:48.17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 53.68 seconds&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 11:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331941#M271991</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-02-12T11:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331942#M271992</link>
      <description>Thank you.</description>
      <pubDate>Sun, 12 Feb 2017 11:02:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331942#M271992</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-02-12T11:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331948#M271993</link>
      <description>&lt;P&gt;You are merging annual with daily data. Given that it's Compustat, both dataset probably have identifiers gvkey and datadate, where&amp;nbsp;datadate is the&amp;nbsp;last date of the fiscal year for annual data,, and day of trading for the security data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question:&amp;nbsp; do you want to merge the security data with the immediately PRECEDING annual data, or the FOLLOWING annual data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And also, are you going to allow for the fact that accounting data is not usually reported until about 45 days after the fiscal year?&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 12:35:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331948#M271993</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-12T12:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331958#M271994</link>
      <description>&lt;P&gt;I don't know if it's correct but I would hesitate to say it was. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at your last step and notice how your final results have more than either of your original tables. You need to figure out why this occurs, where and if it makes sense given your data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 14:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331958#M271994</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-12T14:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331967#M271995</link>
      <description>&lt;P&gt;Why is there only about 43 daily records per annual record?&amp;nbsp; There are typiically 200 trading days per year.&amp;nbsp; Do you have instance of annual accounting data for GVKEY's that do no appear in the daily security data file? If so, what do you want to do about it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your program,merging by gvkey, will not produce what you want, unless (for those gvkey's in both datasets) you have precisely the same series of datadates in both datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a program that outputs every daily record (from dataset SEC) merged with the closest following annual record (dataset ANN).&amp;nbsp; Both files are sorted by gvkey datadate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until (ina1 or last.gvkey);
    set sec ann (in=ina1);
    by gvkey datadate;
  end;

  do until (ina2 or last.gvkey);
    set sec (in=ins) ann (in=ina2 keep=gvkey datadate);
    by gvkey datadate;
    if ins=1 and ina1=1 then output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The first "do until" reads all the records until an annual record.This gets the annual record variables into the program data vector(pdv).&lt;/LI&gt;
&lt;LI&gt;The second "do until" rereads all the same records.
&lt;OL&gt;
&lt;LI&gt;Note there is a "keep=gvkey datadate" for the ANN dataset.&amp;nbsp; Otherwise all the other annual vars read in by the first do group would be reset to missing&amp;nbsp;with every incoming&amp;nbsp;record, whether from SEC or ANN.&amp;nbsp; And since SEC doesn't have those variables they would stay missing. The "keep=" parameter tells SAS not to revise ANN vars not in the keep list.&lt;/LI&gt;
&lt;LI&gt;Use a new dummy var INA2, because dummy INA1 is still being used in this do group.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;Only incoming records coming from the SEC dataset (INS=1), and for which there was a qualifying ANN record&amp;nbsp;found in the first "do until" (INA1=1) are written out.&amp;nbsp; This eliminates all cases of gvkey in SEC but not not having corresponding ANN records.&lt;/LI&gt;
&lt;LI&gt;If you have, say, two years of SEC records but only one ANN record at the end of the two years, and if you want only the 2nd year of SEC data, then &amp;nbsp;this modification is needed, that uses a date_cutoff of 1 year prior to the annual datadate:&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until (ina1 or last.gvkey);
    set sec ann (in=ina1);
    by gvkey datadate;
  end;

  if ina1 then date_cutoff=intnx('year',datadate,-1,'same')+1;

  do until (ina2 or last.gvkey);
    set sec (in=ins) ann (in=ina2 keep=gvkey datadate);
    by gvkey datadate;
    if ins=1 and ina1=1 and datadate&amp;gt;=date_cutoff then output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 16:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331967#M271995</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-12T16:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331998#M271996</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/123993"&gt;@Theo_Gh&lt;/a&gt;, in your log there is a message:&lt;/P&gt;
&lt;PRE&gt;19   data data3;
20       merge theo.to_be_merged(in=a) theo.security_daily(in=b);
21       by gvkey;
22       if b;
23   run;
 
&lt;STRONG&gt;NOTE: MERGE statement has more than one data set with repeats of BY values.&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;that means, your datasets are in relation N:M per gvkey.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run next test code and compare results of merge vs sql -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data tst_nok vs tst_ok:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* merge M:n vs SQL */
data tst1;
  key = 1; varn = 5; varx='A'; output;
  key = 1; varn = 6; varx='B'; output;
  key = 1; varn = 7; varx='C'; output;
run;

data tst2;
  key = 1; varm = 8; vary='X'; output;
  key = 1; varm = 9; vary='Y'; output;
run;

data tst_nok;
merge tst1 tst2;
  by key;
run;

proc sql;
  create table tst_ok as 
  select a.*, b.varm, b.vary
  from tst1 as a
  left join tst2 as b 
  on a.key = b.key
  order by key,varn;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I recommend use sql to join data from both datasets or&lt;/P&gt;
&lt;P&gt;use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;code if it fits your needs.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 20:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331998#M271996</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-12T20:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332065#M271997</link>
      <description>Thank you very much. Will try it.</description>
      <pubDate>Mon, 13 Feb 2017 05:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332065#M271997</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-02-13T05:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332066#M271998</link>
      <description>&lt;P&gt;Thank you very much.I did run your codes and got this:&lt;BR /&gt;NOTE: There were 86856448 observations read from the data set THEO.COPY_SECURITY.&lt;BR /&gt;NOTE: There were 373633 observations read from the data set THEO.COPY_COMPUSTAT.&lt;BR /&gt;NOTE: There were 86856448 observations read from the data set THEO.COPY_SECURITY.&lt;BR /&gt;NOTE: There were 373633 observations read from the data set THEO.COPY_COMPUSTAT.&lt;BR /&gt;NOTE: The data set WORK.WANT has 78137460 observations and 45 variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I noticed that the annual data has been matched against the daily data so that's good. But I have to merge the 'want' data set with other annual data sets. Will a simple proc sort by fyear help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you once again for your time and help !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 05:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332066#M271998</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-02-13T05:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332140#M271999</link>
      <description>&lt;P&gt;Your "want" dataset has 7.8M records, but&amp;nbsp; the security dataset had 8.6M.&amp;nbsp; That means there are .8M security records for which there were no matching annual records.&amp;nbsp; I presume that is unsurprising, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does your other annual data look like? Does it have gvkey? You mention fyear (fiscal year).&amp;nbsp; Are you saying that your other annual data does not have datadate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you think that sorting by fyear is neccessary? If your current data is sorted by&amp;nbsp;gvkey / datadate, is it not likely to also already be sorted by gvkey/fiscal year?&amp;nbsp; You can test this by this simple step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set want ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by gvkey fyear;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If SAS produces no "out of order" message on the log for this program, you have demonstrated that the data is already sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also maybe you should have merged all the annual records first (smaller N), then merge with the daily data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: For latecomers to this topic, here's the link to the code that answered the topic question:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331967#M43407" target="_self"&gt;https://communities.sas.com/t5/General-SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/331967#M43407&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 14:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332140#M271999</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-13T14:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332152#M272000</link>
      <description>&lt;P&gt;Thank you very much for your time and patience. I don't know what I would done without this platform.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No, it's not surprising that the daily data is more than the annual data. From the information I have not all the firms are actively trading on the stock exchange.&lt;/P&gt;&lt;P&gt;Yes, I can merge the annual data before merging with the daily data. My question still is: take for instance that I want the market value as of the end of a particular year. If I still simply multiply share price by number of shares outstanding, I'm going to have different values since the daily stock prices have been matched against the annual shares outstanding. In this particular eg i want the share price at the end of the fiscal year times the closest annual number of shares outstanding (which should give me one value). I guess my question is : How do I need to do so that after matching annual and daily data sets I would get one value for an answer ( which should be the end of fiscal year value) and not multiple values, which should be the same nonetheless.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I count on your usual corporation&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 13:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332152#M272000</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-02-13T13:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332193#M272001</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/123993"&gt;@Theo_Gh&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much for your time and patience. I don't know what I would done without this platform.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No, it's not surprising that the daily data is more than the annual data. From the information I have not all the firms are actively trading on the stock exchange.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was asking about&amp;nbsp;the&amp;nbsp;LOSS of .8M SECURITY records, which (I presume) represents daily prices on public stock exchanges. They are ignored by the program because you have no annual data to match them. That's the opposite of your explanation (inactive stock trading). Since the annual data presumably comes from SEC filings extracted by Compustat, either (1) SEC&amp;nbsp; does not have&amp;nbsp;that company's&amp;nbsp;filings (which I believe is not possible for publicly traded firms), or (2) Compustat did not retrieve those filings, or (3) your lost SEC records are recent, and the corresponding SEC filing has yet to be filed or processed by Compustat.&amp;nbsp; My question was whether that indicated a possible research problem in the data your are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The annual Compustat data has the number of outstanding shares at the end of the fiscal year (CSHO&amp;nbsp;- i.e. on the DATADATE of the annual record.&amp;nbsp; Of course the problem is that there is no guarantee that shares outstanding were constant throughout the fiscal year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the standard Compustat securities daily file has not only closing price variable (PRCCD - "Price Closing - Daily"), but also apparently daily common shares outstanding (CSHOC - "Common Shares Outstanding - Current").&amp;nbsp; Does your daily file have these variables? That will solve the problem of calculating marekt value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, please realize there can be more than one security stored under the same GVKEY (i.e. a company may have multiple classes of stocks on the markets).&amp;nbsp; These are distinguished by the variable IID (Issue ID).&amp;nbsp; You should make sure your securities file only has the IID of the standard common stock of the company.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologies to forum participants for getting into Compustat-specific issues&amp;nbsp;so deeply, but the problems here have structural issues that can be generally informative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 14:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332193#M272001</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-13T14:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332217#M272002</link>
      <description>Thank you.&lt;BR /&gt;No, current file does not have them but I'm downloading them now (will take a while; internet is slow). I will do as you have advised and get back. Thank you.</description>
      <pubDate>Mon, 13 Feb 2017 15:57:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332217#M272002</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-02-13T15:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332527#M272003</link>
      <description>&lt;P&gt;I have downloaded the daily security data with&amp;nbsp;IID,&amp;nbsp;PRCCD,CSHOC&amp;nbsp;so I can calculate the daily market value of equity. However, the annual compustat data does not have iid. I'm interested in the market value of equity at the end of the fiscal year or the nearest. If I'm able to get these to match the annual compustat data, it should not present any serious research problem. No?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any way, I tried using the datadata and SEDOL(&lt;SPAN&gt; The Stock Exchange Daily Official List(SEDOL) Code identifies issues) and got similar results as with gvkey.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 09:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332527#M272003</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-02-14T09:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332548#M272004</link>
      <description>&lt;P&gt;When I use sql, I do not get " MERGE statement has more than one data set with repeats of BY values" . But will it work when one data set is annual and the other is daily ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 11:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332548#M272004</guid>
      <dc:creator>Theo_Gh</dc:creator>
      <dc:date>2017-02-14T11:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: merging compustat global annual data and compusat global security daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332560#M272005</link>
      <description>&lt;P&gt;You do not get this message because SQL creates a cartesian product in many-to-many situations.&lt;/P&gt;
&lt;P&gt;See this code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input id value1;
cards;
1 1
1 2
;
run;

data have2;
input id value2;
cards;
1 3
1 4
1 5
;
run;

proc sql;
create table want as select
a.id, a.value1, b.value2
from have1 a inner join have2 b
on a.id = b.id
;
quit;

proc print data=want noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result is&lt;/P&gt;
&lt;PRE&gt;id    value1    value2

 1       1         3  
 1       2         3  
 1       1         4  
 1       2         4  
 1       1         5  
 1       2         5  
&lt;/PRE&gt;
&lt;P&gt;Now a data step works differently:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
merge
  have1 (in=a)
  have2 (in=b)
;
by id;
if a and b;
run;

proc print data=want2 noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You get the NOTE: MERGE statement has more than one data set with repeats of BY values.&lt;BR /&gt;And this is the result:&lt;/P&gt;
&lt;PRE&gt;id    value1    value2

 1       1         3  
 1       2         4  
 1       2         5  
&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Feb 2017 11:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-compustat-global-annual-data-and-compusat-global/m-p/332560#M272005</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-14T11:40:33Z</dc:date>
    </item>
  </channel>
</rss>

