<?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: Join a table with another in long format by two variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Join-a-table-with-another-in-long-format-by-two-variables/m-p/961592#M43181</link>
    <description>&lt;P&gt;Can you show the code you have tried?&amp;nbsp; Curious if you tried a DATA step merge, or SQL approach?&amp;nbsp; It will help people help you to see the code you have tried, along with an explanation whether you are getting errors from your code, or unexpected results.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Mar 2025 17:39:21 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2025-03-11T17:39:21Z</dc:date>
    <item>
      <title>Join a table with another in long format by two variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Join-a-table-with-another-in-long-format-by-two-variables/m-p/961590#M43180</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input Admission :date09. week :$20. Count_path1 Count_path2; 
  format Admission date9.;
cards;
06JUL2014 28w2014  0   21
13JUL2014 29w2014  1   56
20JUL2014 30w2014  0   0
27JUL2014 31w2014  3   1
03AUG2014 32w2014  4   4
10AUG2014 33w2014  0   0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and another one:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input week :$20. Pathogen :$20. Value; ;
cards;
28w2014 path1 23
29w2014 path1 1
30w2014 path2 56
31w2014 path1 67
32w2014 path2 6
33w2014 path2 2
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to get the following?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB3;
  input Admission :date09. week :$20. Count_path1 Count_path2 path1 path2; 
  format Admission date9.;
cards;
06JUL2014 28w2014  0   21  23   0
13JUL2014 29w2014  1   56  1    0
20JUL2014 30w2014  0   0   0    56
27JUL2014 31w2014  3   1   67   0
03AUG2014 32w2014  4   4   0    6
10AUG2014 33w2014  0   0   0    2
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words I would like to join the two tables at week and pathogen variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 17:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Join-a-table-with-another-in-long-format-by-two-variables/m-p/961590#M43180</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2025-03-11T17:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: Join a table with another in long format by two variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Join-a-table-with-another-in-long-format-by-two-variables/m-p/961592#M43181</link>
      <description>&lt;P&gt;Can you show the code you have tried?&amp;nbsp; Curious if you tried a DATA step merge, or SQL approach?&amp;nbsp; It will help people help you to see the code you have tried, along with an explanation whether you are getting errors from your code, or unexpected results.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 17:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Join-a-table-with-another-in-long-format-by-two-variables/m-p/961592#M43181</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-03-11T17:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Join a table with another in long format by two variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Join-a-table-with-another-in-long-format-by-two-variables/m-p/961594#M43182</link>
      <description>&lt;P&gt;To turn VALUE into PATH1 or PATH2 you need to transpose the second dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=db1 out=db1_wide(drop=_name_);
  by week;
  id pathogen;
  var value;
run;

data want ;
  merge db db1_wide;
  by week;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                                     Count_    Count_
      Obs    Admission     week       path1     path2    path1    path2

       1     06JUL2014    28w2014       0        21        23        .
       2     13JUL2014    29w2014       1        56         1        .
       3     20JUL2014    30w2014       0         0         .       56
       4     27JUL2014    31w2014       3         1        67        .
       5     03AUG2014    32w2014       4         4         .        6
       6     10AUG2014    33w2014       0         0         .        2
&lt;/PRE&gt;
&lt;P&gt;To convert the missing values into zeros you could either add the follow lines to your merge step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;path1=sum(path1,0);
path2=sum(path2,0);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or add a call to PROC STDIZE to fill missing values with zeros.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 18:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Join-a-table-with-another-in-long-format-by-two-variables/m-p/961594#M43182</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-11T18:42:50Z</dc:date>
    </item>
  </channel>
</rss>

