<?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 in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Complex-merging/m-p/601912#M18359</link>
    <description>&lt;P&gt;Create a format for the sex:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cntlin;
set ifp;
where nmiss(sex,intercept) = 0 and nmiss(edu,agegr,young_kid,region) = 4;
fmtname = 'sex';
type = 'n';
keep fmtname type sex intercept;
rename sex=start intercept=label;
run;

proc format cntlin=cntlin;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Similarly, extract the data for the more complex value &lt;SPAN&gt;agegr_edu_p&lt;/SPAN&gt;, then join on sex,agegr,edu and apply the format during that.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Nov 2019 09:17:20 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-11-06T09:17:20Z</dc:date>
    <item>
      <title>Complex merging</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Complex-merging/m-p/601910#M18358</link>
      <description>&lt;P&gt;I have a dataset pop_dm that contains individuals with some characteristics. I have another dataset lfp which contains parameters from a logit regression for the labor force participation. I want to use those parameters to calculate in pop_dm the individual probability of being in the labor force. I would like to know if there is a simple way to merge both datasets. The variable intercept from lfp should for instance match individuals by sex only. Similarly, the variable agegr_edu_p (parameters for the interaction agegr and edu) should match by sex, agegr and education. I thus cannot use a single merge statement, because the “by” are not the same for the different parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My first idea was to do it in many data steps, but it looks over complicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 09:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Complex-merging/m-p/601910#M18358</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2019-11-06T09:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Complex merging</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Complex-merging/m-p/601912#M18359</link>
      <description>&lt;P&gt;Create a format for the sex:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cntlin;
set ifp;
where nmiss(sex,intercept) = 0 and nmiss(edu,agegr,young_kid,region) = 4;
fmtname = 'sex';
type = 'n';
keep fmtname type sex intercept;
rename sex=start intercept=label;
run;

proc format cntlin=cntlin;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Similarly, extract the data for the more complex value &lt;SPAN&gt;agegr_edu_p&lt;/SPAN&gt;, then join on sex,agegr,edu and apply the format during that.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 09:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Complex-merging/m-p/601912#M18359</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-06T09:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Complex merging</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Complex-merging/m-p/602096#M18363</link>
      <description>&lt;P&gt;It might help to share the code used to build the model. Several of the modeling procedures have an option to build a special data that can be used to score another data set using the result from the model using Proc PLM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 18:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Complex-merging/m-p/602096#M18363</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-06T18:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Complex merging</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Complex-merging/m-p/602242#M18365</link>
      <description>&lt;P&gt;You could either use SQL joins or data step hash lookups. Below a SQL approach (code not tested).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as
    select 
      p.*,
      t1.intercept,
      t2.agegr_edu_p
    from 
      pop_dm p

      left join
      (
        select sex, intercept
        from lfp
        where not missing(intercept)
      ) t1
      on p.sex=t1.sex

      left join
      (
        select sex, agegr, edu, agegr_edu_p
        from lfp
        where not missing(agegr_edu_p)
      )t2
      on p.sex=t2.sex and p.agegr=t2.agegr and p.edu=t2.edu
    ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And here a hash lookup (not tested).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then
    do;
      if 0 then set lpf(keep=intercept agegr_edu_p);

      dcl hash h1(dataset:'lpf(keep=sex intercept where=(not missing(intercept))');
      h1.defineKey('sex');
      h1.defineData('intercept');
      h1.defineDone();

      dcl hash h2(dataset:'lpf(keep=sex agegr edu agegr_edu_p where=(not missing(agegr_edu_p))');
      h2.defineKey('sex', 'agegr', 'edu');
      h2.defineData('agegr_edu_p');
      h2.defineDone();
    end;

    set pop_dm;
    h1.find();
    h2.find();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 22:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Complex-merging/m-p/602242#M18365</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-06T22:27:27Z</dc:date>
    </item>
  </channel>
</rss>

