<?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: HASH object merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839924#M332085</link>
    <description>&lt;P&gt;There is in the have2 dataset but not have1&lt;/P&gt;</description>
    <pubDate>Fri, 21 Oct 2022 13:15:25 GMT</pubDate>
    <dc:creator>smackerz1988</dc:creator>
    <dc:date>2022-10-21T13:15:25Z</dc:date>
    <item>
      <title>HASH object merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839922#M332083</link>
      <description>&lt;P&gt;Hello I basically want to keep the visit/visitnum from have2 where ANL01FL='Y' and match with visit/visitnum from have1 but also retain the week 12/16 records where aval is missing. Any help with this matter would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input  SUBJID $ PARAMCD $ ADT :$9. VISITNUM :8. VISIT :$12. AVAL :8. ;
infile datalines dlm = '|';
datalines;
1004|EASITOTA|27JUN2022|1|Screening|9.6
1004|EASITOTA|21JUL2022|2|Day 1    |16.3
1004|EASITOTA|03AUG2022|4|Week 2   |8.6
1004|EASITOTA|17AUG2022|5|Week 4   |8.7
1004|EASITOTA|14SEP2022|6|Week 8   |9.6
;
run;

data have2;
input  SUBJID $  ADT :$9. VISITNUM :8. VISIT :$12. ANL01FL :$1. RTT1L28D :8. RTT1G28D :8. SWREL :8.  SWNREL :8. T2CM :8. RTT1L14D :8. RTT1G14D :8. NCUNODEV :8.; 
infile datalines dlm = '|';
datalines;
1004|21JUL2022|2|Day 1	|Y|0|0|0|0|0|0|0|1
1004|03AUG2022|4|Week 2	|Y|0|0|0|0|0|0|0|1
1004|17AUG2022|5|Week 4	|Y|0|0|0|0|0|0|0|1
1004|14SEP2022|6|Week 8	|Y|0|0|0|0|0|0|0|1
1004|13OCT2022|7|Week 12|Y|0|0|0|0|0|0|0|1
1004|10NOV2022|8|Week 16|Y|0|0|0|0|0|0|0|1
;
run;


data want;
input SUBJID $ PARAMCD $ ADT :$9. VISITNUM :8. VISIT :$12. RTT1L28D :8. RTT1G28D :8. SWREL :8.  SWNREL :8. T2CM :8. RTT1L14D :8. RTT1G14D :8. NCUNODEV :8.; 
infile datalines dlm = '|';
datalines;
1004|EASITOTA|21JUL2022|2|Day 1	    |16.3|0|0|0|0|0|0|0|1
1004|EASITOTA|03AUG2022|4|Week 2	|8.6 |0|0|0|0|0|0|0|1
1004|EASITOTA|17AUG2022|5|Week 4	|8.7 |0|0|0|0|0|0|0|1
1004|EASITOTA|14SEP2022|6|Week 8	|9.6 |0|0|0|0|0|0|0|1
1004|EASITOTA|         |7|Week 12   |    |0|0|0|0|0|0|0|1
1004|EASITOTA|         |8|Week 16   |    |0|0|0|0|0|0|0|1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839922#M332083</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2022-10-21T13:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: HASH object merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839923#M332084</link>
      <description>&lt;P&gt;None of the records have&amp;nbsp;&lt;SPAN&gt;ANL01FL='Y'?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839923#M332084</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-21T13:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: HASH object merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839924#M332085</link>
      <description>&lt;P&gt;There is in the have2 dataset but not have1&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839924#M332085</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2022-10-21T13:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: HASH object merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839928#M332087</link>
      <description>&lt;P&gt;No.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seems to me you switched VISIT and ANL01FL in the have2 data, am I right?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the have2 data should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
input  SUBJID $  ADT :$9. VISITNUM :8. VISIT :$12. ANL01FL :$1. RTT1L28D :8. RTT1G28D :8. SWREL :8.  SWNREL :8. T2CM :8. RTT1L14D :8. RTT1G14D :8. NCUNODEV :8.; 
infile datalines dlm = '|';
datalines;
1004|21JUL2022|2|Day 1	|Y|0|0|0|0|0|0|0|1
1004|03AUG2022|4|Week 2	|Y|0|0|0|0|0|0|0|1
1004|17AUG2022|5|Week 4	|Y|0|0|0|0|0|0|0|1
1004|14SEP2022|6|Week 8	|Y|0|0|0|0|0|0|0|1
1004|13OCT2022|7|Week 12|Y|0|0|0|0|0|0|0|1
1004|10NOV2022|8|Week 16|Y|0|0|0|0|0|0|0|1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839928#M332087</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-21T13:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: HASH object merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839930#M332088</link>
      <description>&lt;P&gt;Sorry yes I did make that update shortly after I posted because I thought it would be easier&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839930#M332088</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2022-10-21T13:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: HASH object merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839932#M332090</link>
      <description>&lt;P&gt;Ok.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this gives you what you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input  SUBJID $ PARAMCD $ ADT :$9. VISITNUM :8. VISIT :$12. AVAL :8. ;
infile datalines dlm = '|';
datalines;
1004|EASITOTA|21JUL2022|2|Day 1    |16.3
1004|EASITOTA|03AUG2022|4|Week 2   |8.6
1004|EASITOTA|17AUG2022|5|Week 4   |8.7
1004|EASITOTA|14SEP2022|6|Week 8   |9.6
;
run;

data have2;
input  SUBJID $  ADT :$9. VISITNUM :8. VISIT :$12. ANL01FL :$1. RTT1L28D :8. RTT1G28D :8. SWREL :8.  SWNREL :8. T2CM :8. RTT1L14D :8. RTT1G14D :8. NCUNODEV :8.; 
infile datalines dlm = '|';
datalines;
1004|21JUL2022|2|Day 1	|Y|0|0|0|0|0|0|0|1
1004|03AUG2022|4|Week 2	|Y|0|0|0|0|0|0|0|1
1004|17AUG2022|5|Week 4	|Y|0|0|0|0|0|0|0|1
1004|14SEP2022|6|Week 8	|Y|0|0|0|0|0|0|0|1
1004|13OCT2022|7|Week 12|Y|0|0|0|0|0|0|0|1
1004|10NOV2022|8|Week 16|Y|0|0|0|0|0|0|0|1
;
run;

data want(drop = rc ANL01FL);

   format SUBJID PARAMCD ADT VISITNUM VISIT AVAL RTT1L28D RTT1G28D SWREL SWNREL T2CM RTT1L14D RTT1G14D NCUNODEV;

   if _N_ = 1 then do;
      dcl hash h(dataset : 'have1');
      h.definekey('SUBJID', 'VISITNUM');
      h.definedata(all : 'Y');
      h.definedone();
   end;

   set have2;
   where ANL01FL='Y';

   if 0 then set have1;

   rc = h.find();

   if rc then call missing(ADT, AVAL);

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839932#M332090</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-21T13:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: HASH object merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839935#M332093</link>
      <description>&lt;P&gt;This works great thanks.&amp;nbsp; My only issue is when I apply it to the actual datasets it only populates for the formatted columns but what do you do if there are multiple other column variables in both datasets?. is it the&amp;nbsp; if 0= set statement at the start instead of formats?. Does that make sense?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839935#M332093</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2022-10-21T13:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: HASH object merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839936#M332094</link>
      <description>&lt;OL&gt;
&lt;LI&gt;What do you mean by&amp;nbsp;&lt;SPAN&gt;it only populates for the formatted columns?&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;The if 0 then set statement makes the variables from have1 available in the PDV and ready for hash lookup.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;The Format Statement at the beginning simply controls the order of variables.&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;More variables in the data should not be a problem here.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839936#M332094</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-21T13:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: HASH object merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839938#M332095</link>
      <description>&lt;P&gt;you're 100% correct I know what the issue was now. I think I need to remove the ANL01FL actually from the equation as it's causing unexpected events but if I just remove the where clause referencing&amp;nbsp;ANL01FL it doesn't seem to work. How would you do it if&amp;nbsp;ANL01FL didn't exist or is it the exact same approach?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839938#M332095</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2022-10-21T13:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: HASH object merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839941#M332097</link>
      <description>&lt;P&gt;Same approach, simply remove it from the Where and Drop statements like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input  SUBJID $ PARAMCD $ ADT :$9. VISITNUM :8. VISIT :$12. AVAL :8. ;
infile datalines dlm = '|';
datalines;
1004|EASITOTA|21JUL2022|2|Day 1    |16.3
1004|EASITOTA|03AUG2022|4|Week 2   |8.6
1004|EASITOTA|17AUG2022|5|Week 4   |8.7
1004|EASITOTA|14SEP2022|6|Week 8   |9.6
;
run;

data have2;
input  SUBJID $  ADT :$9. VISITNUM :8. VISIT :$12. RTT1L28D :8. RTT1G28D :8. SWREL :8.  SWNREL :8. T2CM :8. RTT1L14D :8. RTT1G14D :8. NCUNODEV :8.; 
infile datalines dlm = '|';
datalines;
1004|21JUL2022|2|Day 1	|0|0|0|0|0|0|0|1
1004|03AUG2022|4|Week 2	|0|0|0|0|0|0|0|1
1004|17AUG2022|5|Week 4	|0|0|0|0|0|0|0|1
1004|14SEP2022|6|Week 8	|0|0|0|0|0|0|0|1
1004|13OCT2022|7|Week 12|0|0|0|0|0|0|0|1
1004|10NOV2022|8|Week 16|0|0|0|0|0|0|0|1
;
run;

data want(drop = rc);

   format SUBJID PARAMCD ADT VISITNUM VISIT AVAL RTT1L28D RTT1G28D SWREL SWNREL T2CM RTT1L14D RTT1G14D NCUNODEV;

   if _N_ = 1 then do;
      dcl hash h(dataset : 'have1');
      h.definekey('SUBJID', 'VISITNUM');
      h.definedata(all : 'Y');
      h.definedone();
   end;

   set have2;

   if 0 then set have1;

   rc = h.find();

   if rc then call missing(ADT, AVAL);

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HASH-object-merge/m-p/839941#M332097</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-21T13:51:40Z</dc:date>
    </item>
  </channel>
</rss>

