<?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: Complex merging when data in one dataset is in rows and the other is in columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Complex-merging-when-data-in-one-dataset-is-in-rows-and-the/m-p/621039#M182520</link>
    <description>&lt;P&gt;No I need just one dummy variable. The output should be the same as the test table plus one more dummy.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jan 2020 03:32:24 GMT</pubDate>
    <dc:creator>Agent1592</dc:creator>
    <dc:date>2020-01-30T03:32:24Z</dc:date>
    <item>
      <title>Complex merging when data in one dataset is in rows and the other is in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Complex-merging-when-data-in-one-dataset-is-in-rows-and-the/m-p/621025#M182516</link>
      <description>&lt;P&gt;Dear SAS community:&lt;/P&gt;&lt;P&gt;I have two datasets. The first called "test1" is quarterly data for firms that have operations in certain states. If the value for the State Abbreviation is greater than 0 then the firm has operations in that state. The second dataset called test2 and has the states that were affected by some negative economic shock. I am trying to merge the two datasets and test is the leading dataset.&amp;nbsp; I am interested in creating a dummy variable=1 if the firm has operations in certain states (State Abbreviation in the "test" dataset&amp;gt;0) and this state is affected by negative economic shock (stateid is in "test2" dataset). The dummy variable=0 if the firm has operations in certain states (state Abbreviation in the "test" dataset&amp;gt;0) and this state is not affected by negative economic shock (stateid is not in the second dataset) or if the firm has no operations in certain states (State variable in test=0) and this state is&amp;nbsp; affected by negative economic shock (stateid is in the second dataset). It is almost like some kind of matrix multiplication task.&amp;nbsp;&lt;/P&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 WORK.TEST;
  infile datalines dsd truncover;
  input CID:$10. year:32. qtr:32. AL:32. AZ:32. AR:32. CA:32. CO:32. CT:32. DE:32. FL:32. GA:32. HI:32. ID:32. IL:32. IN:32. IA:32. KS:32. KY:32. LA:32. ME:32. MD:32. MA:32. MI:32. MN:32. MS:32. MO:32. MT:32. NE:32. NV:32. NH:32. NJ:32. NM:32. NY:32. NC:32. ND:32. OH:32. OK:32. OR:32. PA:32. RI:32. SC:32. SD:32. TN:32. TX:32. UT:32. VT:32. VA:32. WA:32. WV:32. WI:32. WY:32.;
  label CID="Company ID";
datalines4;
0000061478,2005,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0
0000061478,2005,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0
0000061478,2005,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0
0000061478,2005,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0
0000006201,2005,1,0,2,0,3,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,12,0,0,0,2,0,0,0,0,0,0,3,0,0,0,2,0,0,0
0000006201,2005,2,0,2,0,3,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,12,0,0,0,2,0,0,0,0,0,0,3,0,0,0,2,0,0,0
0000006201,2005,3,0,2,0,3,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,12,0,0,0,2,0,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1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,4,0
0000004515,2005,1,0,2,0,3,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,10,0,0,0,2,0,0,0,0,0,0,3,0,0,0,2,0,0,0
0000004515,2005,2,0,2,0,3,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,10,0,0,0,2,0,0,0,0,0,0,3,0,0,0,2,0,0,0
0000004515,2005,3,0,2,0,3,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,10,0,0,0,2,0,0,0,0,0,0,3,0,0,0,2,0,0,0
0000004515,2005,4,0,2,0,3,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,10,0,0,0,2,0,0,0,0,0,0,3,0,0,0,2,0,0,0
0000771497,2005,1,0,0,0,27,2,0,2,6,1,2,0,0,0,0,0,0,0,0,1,0,0,2,0,0,0,2,0,0,0,0,13,0,0,0,0,2,3,0,0,0,0,8,0,0,1,5,0,0,0
0000771497,2005,2,0,0,0,27,2,0,2,6,1,2,0,0,0,0,0,0,0,0,1,0,0,2,0,0,0,2,0,0,0,0,13,0,0,0,0,2,3,0,0,0,0,8,0,0,1,5,0,0,0
0000771497,2005,3,0,0,0,27,2,0,2,6,1,2,0,0,0,0,0,0,0,0,1,0,0,2,0,0,0,2,0,0,0,0,13,0,0,0,0,2,3,0,0,0,0,8,0,0,1,5,0,0,0
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.TEST2;
  infile datalines dsd truncover;
  input Year:32. Quarter:32. state_id:$2.;
datalines4;
2005,3,AL
2005,3,AR
2005,3,CT
2005,3,FL
2005,3,GA
2005,3,IA
2005,3,IL
2005,3,IN
2005,3,KS
2005,3,KY
2005,3,LA
2005,3,MA
2005,3,MD
2005,3,ME
2005,3,MI
2005,3,MO
2005,3,MS
2005,3,NC
2005,3,NH
2005,3,NJ
2005,3,NY
2005,3,OH
2005,3,PA
2005,3,RI
2005,3,SC
2005,3,TN
2005,3,TX
2005,3,VA
2005,3,VT
2005,3,WV
;;;;&lt;/CODE&gt;&lt;/PRE&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>Thu, 30 Jan 2020 00:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Complex-merging-when-data-in-one-dataset-is-in-rows-and-the/m-p/621025#M182516</guid>
      <dc:creator>Agent1592</dc:creator>
      <dc:date>2020-01-30T00:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Complex merging when data in one dataset is in rows and the other is in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Complex-merging-when-data-in-one-dataset-is-in-rows-and-the/m-p/621032#M182518</link>
      <description>&lt;P&gt;This is the approach I used.&lt;/P&gt;&lt;P&gt;From the TEST dataset create a long table (transposed) and then compare it with TEST2.&lt;/P&gt;&lt;P&gt;I created table only for those impacted as otherwise I was assuming variable=0. You can change criteria if I missed something but it gives you one of the ideas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*sort so that we can transpose;
proc sort data=test;
by cid year qtr;

*create a long table instead of wide;
proc transpose data=test out=test5(rename=(_name_=state_id col1=state_value));
by cid year qtr;
var AL AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT 
		NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY;

*those that have been affected by economy;
DATA test6;
SET test5;
FORMAT year quarter 4. state_id $2.;
  IF _n_ = 1 THEN DO; 
    DECLARE hash ht(DATASET:'test2');
    ht.defineKey('year','quarter','state_id');
    ht.defineDone();
  END;

	rc = ht.check(key:year, key:qtr, key:state_id);

	*your criteria for those where value &amp;gt; 0 and impacted by economy;
	IF rc=0 AND state_value &amp;gt; 0; 
	variable = 1;
DROP rc quarter;
RUN;

*get unique companies for each year,quarter;
PROC SQL; CREATE TABLE test7 AS SELECT distinct cid, year, qtr, variable FROM test6;

*merge back those that have been affected;
PROC SQL; CREATE TABLE test_final AS 
SELECT a.*, COALESCE(b.variable,0) as variable 
FROM test a 
	LEFT JOIN test7 b 
		ON a.cid=b.cid AND a.year=b.year AND a.qtr=b.qtr;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 02:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Complex-merging-when-data-in-one-dataset-is-in-rows-and-the/m-p/621032#M182518</guid>
      <dc:creator>plevcek</dc:creator>
      <dc:date>2020-01-30T02:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Complex merging when data in one dataset is in rows and the other is in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Complex-merging-when-data-in-one-dataset-is-in-rows-and-the/m-p/621037#M182519</link>
      <description>&lt;P&gt;Show us&amp;nbsp; how your expected output should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want multiple dummy variables if the same firm has presence in multiple states?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 03:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Complex-merging-when-data-in-one-dataset-is-in-rows-and-the/m-p/621037#M182519</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-01-30T03:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Complex merging when data in one dataset is in rows and the other is in columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Complex-merging-when-data-in-one-dataset-is-in-rows-and-the/m-p/621039#M182520</link>
      <description>&lt;P&gt;No I need just one dummy variable. The output should be the same as the test table plus one more dummy.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 03:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Complex-merging-when-data-in-one-dataset-is-in-rows-and-the/m-p/621039#M182520</guid>
      <dc:creator>Agent1592</dc:creator>
      <dc:date>2020-01-30T03:32:24Z</dc:date>
    </item>
  </channel>
</rss>

