<?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: Lookup and Merging in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70311#M20228</link>
    <description>To be more specific:&lt;BR /&gt;
IF you chose to use data step and MERGE, use IN= option together with a subsetting if, e.g.:&lt;BR /&gt;
IF a AND b;&lt;BR /&gt;
&lt;BR /&gt;
If you use SQL, specify an SQL with an inner join.&lt;BR /&gt;
&lt;BR /&gt;
If you have code errors, please attach them together with your code, then could get some more specific help.&lt;BR /&gt;
&lt;BR /&gt;
This is considered as quite basic programming. If you will continue to use SAS, I encourage you to take some SAS classes (programming and SQL).&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
    <pubDate>Tue, 23 Mar 2010 13:20:48 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2010-03-23T13:20:48Z</dc:date>
    <item>
      <title>Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70308#M20225</link>
      <description>I have two tables.&lt;BR /&gt;
The first table contains:&lt;BR /&gt;
ISIN       |         Stock        |       Dividend Date&lt;BR /&gt;
&lt;BR /&gt;
The second table contains the stock returns of all the stocks in a country over a time horizon of several years.&lt;BR /&gt;
ISIN       |    Stock Price&lt;BR /&gt;
&lt;BR /&gt;
I want to merge the two. The merged table should give me:&lt;BR /&gt;
ISIN       |    Stock       |       Dividend Date    |     Stock Price on Dividend Date&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
So I'd have to first ensure that the ISIN of the company matches, and then I need SAS to look up the stock price only on the dividend date. &lt;BR /&gt;
I'm not really sure how to program it. Can anyone help?&lt;BR /&gt;
Thank you.</description>
      <pubDate>Tue, 23 Mar 2010 12:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70308#M20225</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-23T12:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70309#M20226</link>
      <description>Investigate using SAS PROC SQL  and JOIN processing to relate the two file sources.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Recommended Google advanced  search argument, this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
sql procedure join processing merge site:sas.com</description>
      <pubDate>Tue, 23 Mar 2010 12:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70309#M20226</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-03-23T12:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70310#M20227</link>
      <description>Thanks Scott. &lt;BR /&gt;
Can you be a bit more specific? I'm not very familiar with SAS and already looked at lots of examples in the help files, but still get error messages.</description>
      <pubDate>Tue, 23 Mar 2010 13:05:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70310#M20227</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-23T13:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70311#M20228</link>
      <description>To be more specific:&lt;BR /&gt;
IF you chose to use data step and MERGE, use IN= option together with a subsetting if, e.g.:&lt;BR /&gt;
IF a AND b;&lt;BR /&gt;
&lt;BR /&gt;
If you use SQL, specify an SQL with an inner join.&lt;BR /&gt;
&lt;BR /&gt;
If you have code errors, please attach them together with your code, then could get some more specific help.&lt;BR /&gt;
&lt;BR /&gt;
This is considered as quite basic programming. If you will continue to use SAS, I encourage you to take some SAS classes (programming and SQL).&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Tue, 23 Mar 2010 13:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70311#M20228</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2010-03-23T13:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70312#M20229</link>
      <description>Tina,&lt;BR /&gt;
&lt;BR /&gt;
I see that the second table contains the identification number and stock price but its over several years, is there a date associated with this table?&lt;BR /&gt;
&lt;BR /&gt;
If you are not quite familiar with SQL, you can use multiple datasteps:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=table1;&lt;BR /&gt;
  by isin;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=table2;&lt;BR /&gt;
  by isin;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data combined;&lt;BR /&gt;
  merge table1 table2;&lt;BR /&gt;
  by isin;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
***This data contains only those that merge and match isin;&lt;BR /&gt;
data matching;&lt;BR /&gt;
	set combined;&lt;BR /&gt;
	if nmiss(isin,stock,divdt,stockprice)=0;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=matching;  title1 'Matching'; run;&lt;BR /&gt;
&lt;BR /&gt;
***If you need the set with the differences, use this;&lt;BR /&gt;
data diffs;&lt;BR /&gt;
	set combined;&lt;BR /&gt;
	if nmiss(isin,stock,divdt,stockprice)&amp;gt;0;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=diffs; title1 'Differences'; run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Hope this helps!</description>
      <pubDate>Tue, 23 Mar 2010 13:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70312#M20229</guid>
      <dc:creator>RPGarland</dc:creator>
      <dc:date>2010-03-23T13:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70313#M20230</link>
      <description>Thanks a lot! You're right, in table 2 I have the dates and stock prices. When I merge the two tables using 'merge' function, I obtain all stock prices for a particular company over time. However, I only want the stock price on the particular date that I had specified in table 1. How can I incorporate that?&lt;BR /&gt;
Thanks!</description>
      <pubDate>Tue, 23 Mar 2010 13:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70313#M20230</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-23T13:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70314#M20231</link>
      <description>Tina,&lt;BR /&gt;
&lt;BR /&gt;
It would help if you put some sample code or how the variables were named.  But if the date variables are the same, you can add the date variable to the sort statements and the merge statement.&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=table1;&lt;BR /&gt;
by isin DIVDT;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=table2;&lt;BR /&gt;
by isin DIVDT;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data combined;&lt;BR /&gt;
merge table1 table2;&lt;BR /&gt;
by isin DIVDT;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
***This data contains only those that merge and match isin;&lt;BR /&gt;
data matching;&lt;BR /&gt;
set combined;&lt;BR /&gt;
if nmiss(isin,stock,divdt,stockprice)=0;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=matching; title1 'Matching'; run;&lt;BR /&gt;
&lt;BR /&gt;
***If you need the set with the differences, use this;&lt;BR /&gt;
data diffs;&lt;BR /&gt;
set combined;&lt;BR /&gt;
if nmiss(isin,stock,divdt,stockprice)&amp;gt;0;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=diffs; title1 'Differences'; run;&lt;BR /&gt;
&lt;BR /&gt;
That should help.  If the date variables are different, you neet to rename a variable to match the variable that you are using to merge.</description>
      <pubDate>Tue, 23 Mar 2010 14:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70314#M20231</guid>
      <dc:creator>RPGarland</dc:creator>
      <dc:date>2010-03-23T14:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70315#M20232</link>
      <description>Thanks. &lt;BR /&gt;
Ok, I have in table A:&lt;BR /&gt;
ISIN    |     Issuer    |   DivDate&lt;BR /&gt;
&lt;BR /&gt;
In table B, I have:&lt;BR /&gt;
ISIN    |     Issuer    |  TradeDate   |  Stock Price&lt;BR /&gt;
&lt;BR /&gt;
Table B is a very large file with stock prices for many companies on each trading day. &lt;BR /&gt;
I sorted both tables by ISIN. Now I want to combine the two table. In the combined table I want to have:&lt;BR /&gt;
ISIN    |    Issuer     |  DivDate      |    Stock Price&lt;BR /&gt;
&lt;BR /&gt;
So the combined table should only show me the stock price of a particular company on the dividend date. In Excel, I would use LOOKUP function, so only if TradeDate = DivDate do I want to get a result. But I'm not sure what I have to do in SAS. &lt;BR /&gt;
So far, I sorted both tables by ISIN, and I will also merge by ISIN, but I need the conditional statement TradeDate=DivDate. All other observations from Table 2 should not appear in the new table.&lt;BR /&gt;
I hope that makes it more clear. &lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Tue, 23 Mar 2010 14:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70315#M20232</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-23T14:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70316#M20233</link>
      <description>You will need to be more precise with SAS - there is no fuzzy MERGE.  My suggestion is that you "interleave" instead, using a SET with a BY and correlate the two files' SAS variables possibly using a RETAIN statement (with temporary variables) and carry forward data variables.  You will want to read-about and use the BY GROUP PROCESSING concept with the SET / BY statement combination in conjunction with IF FIRST.&lt;BREAK_VARIABLE&gt;  and also possibly  IF LAST.&lt;BREAK_VARIABLE&gt;  to perform your data association and analysis.&lt;BR /&gt;
&lt;BR /&gt;
Another option is to identify the source data variable values you need to analyze (in your smaller file) and then load a HASH table for in-memory data variable comparisons, where you can use GT / GE / LT / LE / etc.&lt;BR /&gt;
&lt;BR /&gt;
As was mentioned, you're new to SAS and it's going to be important to delve into the SAS Base documentation and also make use of the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website's reference materials, including sample code, topic-related papers, and SAS-hosted documentation.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Google advanced search arguments, this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
table lookup site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
data step programming by group processing site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
data step hash object site:sas.com&lt;/BREAK_VARIABLE&gt;&lt;/BREAK_VARIABLE&gt;</description>
      <pubDate>Tue, 23 Mar 2010 15:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70316#M20233</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-03-23T15:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70317#M20234</link>
      <description>Is it not as easy as an inner join?&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table newtable as select a.*,b.StockPrice from &lt;BR /&gt;
  (select * from table1) as a&lt;BR /&gt;
     inner join &lt;BR /&gt;
  (select * from table2) as b&lt;BR /&gt;
     on a.ISIN = b.ISIN&lt;BR /&gt;
     and a.Issuer = b.Issuer&lt;BR /&gt;
     and a.DivDate = b.TradeDate &lt;BR /&gt;
 ;&lt;BR /&gt;
quit;</description>
      <pubDate>Tue, 23 Mar 2010 15:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70317#M20234</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2010-03-23T15:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70318#M20235</link>
      <description>Thanks Scott. I know that I have to read more about the SAS Basics, unfortunately I don't have time to do that for this project as deadline approaches soon. Now, given that it looks like that there are many different ways to program in SAS and my dataset is quite large which doesn't allow me to doublecheck the results one-by-one, I need to make sure that the statement I use is correct. I already looked at lots of documents decribing the MERGE function, but there's no concrete example to what I need, mainly it's only merging by one or several variable, nothing about merging conditional or lookup. Also, the data observations in Table 1 should not decrease. So if, for example, Table 2 does not show a stock price on all Trading Dates and it effects the merging in a way that I don't have a stock price from Table 2 for the DivDate in Table 1, Table 1 should still keep the record of the stock, but then show for the stock price on the div date '.'.</description>
      <pubDate>Tue, 23 Mar 2010 15:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70318#M20235</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-23T15:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70319#M20236</link>
      <description>Given the "pickle" you're in, I'd recommend a PROC SQL approach with focus on JOIN as a means to correlate your inputs.  There are ways to code inner/nested queries so to optimize the "transaction file processing" you need to perform, given the large input.  &lt;BR /&gt;
&lt;BR /&gt;
You would benefit from generating a "candidate data" subset file, saving it to a permanent SAS data library (with the LIBNAME statement), and then work with that data sample to develop a SAS program using PROC SQL that solves your information analysis requirement.&lt;BR /&gt;
&lt;BR /&gt;
Most definitely, return to the forum as you work through the process, to address any particular problem you may encounter.  At some point, you will want and need to own your SAS programming experience, if not more than to be able to support the code going forward.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 23 Mar 2010 16:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70319#M20236</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-03-23T16:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70320#M20237</link>
      <description>Thanks a lot, this looks like I was looking for. &lt;BR /&gt;
Just have to figure out the syntax at the start now as I still get error messages I typed: &lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table mw.newtable&lt;BR /&gt;
as select divdates.*, mktdates.prices,&lt;BR /&gt;
from mw.divdates,&lt;BR /&gt;
inner join mw.mktdates&lt;BR /&gt;
on divdates.isin = mktdates.isin&lt;BR /&gt;
and divdates.divdate = mktdates.mktdate;&lt;BR /&gt;
quit&lt;BR /&gt;
&lt;BR /&gt;
I suspect some errors at the start, but am not sure what's wrong.</description>
      <pubDate>Tue, 23 Mar 2010 16:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70320#M20237</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-23T16:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup and Merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70321#M20238</link>
      <description>It's a good idea to share your SAS log (pasted in a reply) with the exact error messages, so others don't spend time guessing your problem.&lt;BR /&gt;
&lt;BR /&gt;
And, if/when you paste code, sometimes you should follow guidelines at the link below (recommend bookmarking it as a favorite for future posts):&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 23 Mar 2010 17:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-and-Merging/m-p/70321#M20238</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-03-23T17:44:20Z</dc:date>
    </item>
  </channel>
</rss>

