<?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: Help with the data in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260147#M57516</link>
    <description>&lt;P&gt;Any help???&lt;/P&gt;</description>
    <pubDate>Wed, 30 Mar 2016 16:12:12 GMT</pubDate>
    <dc:creator>pp2014</dc:creator>
    <dc:date>2016-03-30T16:12:12Z</dc:date>
    <item>
      <title>Help with the data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260136#M57515</link>
      <description>&lt;P&gt;I have a data in file1 as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data file1;&lt;/P&gt;
&lt;P&gt;input prd $3. id $2. terr $4. x y z ;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;ABC 11 M123 &amp;nbsp;0 1 5&lt;/P&gt;
&lt;P&gt;ABC 11 M345 &amp;nbsp;1 0 2&lt;/P&gt;
&lt;P&gt;ABC 12 M123 &amp;nbsp;0 2 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data file2;&lt;/P&gt;
&lt;P&gt;input prd $3. id $2. terr $4. x y z ;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;XYZ 11 M123 2 0 3&lt;/P&gt;
&lt;P&gt;XYZ 13 M123 1 0 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want output for the file1 and file2 as follow (basically I want all id and terr to be shown in both files only with 0 values if they originally don't exist) :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;file1 will have the following data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ABC 11 M123 &amp;nbsp;0 1 5&lt;/P&gt;
&lt;P&gt;ABC 11 M345 &amp;nbsp;1 0 2&lt;/P&gt;
&lt;P&gt;ABC 12 M123 &amp;nbsp;0 2 3&lt;/P&gt;
&lt;P&gt;ABC 13 M123 &amp;nbsp;0 0 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;file2 will have the following data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;XYZ 11 M123 &amp;nbsp; 2 0 3&lt;/P&gt;
&lt;P&gt;XYZ 11 M345 &amp;nbsp; 0 0 0&lt;/P&gt;
&lt;P&gt;xyz &amp;nbsp;12 M123 &amp;nbsp; 0 0 0&lt;/P&gt;
&lt;P&gt;XYZ 13 M123 &amp;nbsp;1 0 3&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 15:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260136#M57515</guid>
      <dc:creator>pp2014</dc:creator>
      <dc:date>2016-03-30T15:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Help with the data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260147#M57516</link>
      <description>&lt;P&gt;Any help???&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 16:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260147#M57516</guid>
      <dc:creator>pp2014</dc:creator>
      <dc:date>2016-03-30T16:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Help with the data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260149#M57517</link>
      <description>&lt;P&gt;It's not 100% clear how many variables you actually have and what should be hard-coded, but here's an approach anyway.&amp;nbsp; If the data sets are not already sorted, start there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=file1;&lt;/P&gt;
&lt;P&gt;by id terr;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=file2;&lt;/P&gt;
&lt;P&gt;by id terr;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then combine:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data new_file1;&lt;/P&gt;
&lt;P&gt;merge file1 (in=in1) file2 (keep=id terr);&lt;/P&gt;
&lt;P&gt;by id terr;&lt;/P&gt;
&lt;P&gt;if in1=0 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; prd='ABC';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; x=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; y=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; z=0;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then similarly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data new_file2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; merge file1 (keep=id terr) file2 (in=in2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id terr;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if in2=0 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prd='XYZ';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; z=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 16:20:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260149#M57517</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-30T16:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Help with the data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260293#M57535</link>
      <description>&lt;PRE&gt;
data file1;
input prd $ id $ terr $ x y z ;
cards;
ABC 11 M123  0 1 5
ABC 11 M345  1 0 2
ABC 12 M123  0 2 3
;
run;
 
data file2;
input prd $ id $ terr $ x y z ;
cards;
XYZ 11 M123 2 0 3
XYZ 13 M123 1 0 3
;
run;

data want1;
 merge file1 file2(keep=id terr);
 by id terr;
 length new_prd $ 40;
 retain new_prd ;
 new_prd=coalescec(new_prd ,prd);
 x=coalesce(x,0);
 y=coalesce(y,0);
 z=coalesce(z,0);
 drop prd;
run;

data want2;
 merge file2 file1(keep=id terr);
 by id terr;
 length new_prd $ 40;
 retain new_prd ;
 new_prd=coalescec(new_prd ,prd);
 x=coalesce(x,0);
 y=coalesce(y,0);
 z=coalesce(z,0);
 drop prd;
run;


&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2016 02:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260293#M57535</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-31T02:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help with the data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260295#M57536</link>
      <description>&lt;P&gt;One more!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data file1;
length prd $3 id $2 terr $4;
input prd id terr x y z ;
cards;
ABC 11 M123  0 1 5
ABC 11 M345  1 0 2
ABC 12 M123  0 2 3
;
data file2;
length prd $3 id $2 terr $4;
input prd id terr x y z ;
cards;
XYZ 11 M123 2 0 3
XYZ 13 M123 1 0 3
;

proc sql;
create table new_file1 as
select a.prd, b.id, b.terr, 
    coalesce(x, 0) as x,
    coalesce(y, 0) as y,
    coalesce(z, 0) as z
from
((select unique prd from file1) as a
 cross join 
 (   select id, terr from file1 
     union
     select id, terr from file2 ) as b)
left join file1 as c on b.id=c.id and b.terr=c.terr;

create table new_file2 as
select a.prd, b.id, b.terr, 
    coalesce(x, 0) as x,
    coalesce(y, 0) as y,
    coalesce(z, 0) as z
from
((select unique prd from file2) as a
 cross join 
 (   select id, terr from file2 
     union
     select id, terr from file1 ) as b)
left join file2 as c on b.id=c.id and b.terr=c.terr;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2016 02:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-the-data/m-p/260295#M57536</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-03-31T02:30:36Z</dc:date>
    </item>
  </channel>
</rss>

