<?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: Multiple records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600453#M173572</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards missover;
input ID	(Visit	Test) (&amp;amp; $10.)	res;
cards;
1001	Screen	Height	170
1001	Screen	Weight	82
1001	Screen	Height	 
1001	Screen	Weight	82
1001	Day 1	Height	170
1001	Day 1	Weight	89
1001	Day 1	Height	170
1001	Day 1	Weight	 
1002	Screen	Height	180
1002	Screen	Weight	95
1002	Day 1	Height	180
1002	Day 1	Weight	95
;


data want ;
if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("id","test","res") ;
   h.definedata ("id","test","res") ;
   h.definedone () ;
end;
set have;
where res&amp;gt;.;
if h.check() ne 0;
 rc=h.add();
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;&amp;nbsp; A best time to recommend a solution beautifully demonstrated by geniuses&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13569"&gt;@DonH&lt;/a&gt;&amp;nbsp; in their book.&lt;/P&gt;
&lt;DIV class="text parbase section"&gt;
&lt;DIV class=""&gt;
&lt;H3&gt;Data Management Solutions Using SAS&lt;SUP&gt;®&lt;/SUP&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Hash Table Operations: A Business Intelligence Case Study&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/H3&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="text parbase section"&gt;
&lt;DIV class=""&gt;
&lt;P&gt;&lt;SPAN class="xsmall-txt-light"&gt;By&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://support.sas.com/en/books/authors/paul-dorfman.html" target="_blank" rel="noopener"&gt;Paul Dorfman&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://support.sas.com/en/books/authors/don-henderson.html" target="_blank" rel="noopener"&gt;Don Henderson&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="xsmall-txt-light"&gt;I plagiarized their solution but why not. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 30 Oct 2019 16:57:39 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-10-30T16:57:39Z</dc:date>
    <item>
      <title>Multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600443#M173566</link>
      <description>&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Visit&lt;/TD&gt;&lt;TD&gt;Test&lt;/TD&gt;&lt;TD&gt;res&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;Screen&lt;/TD&gt;&lt;TD&gt;Height&lt;/TD&gt;&lt;TD&gt;170&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;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;/TD&gt;&lt;TD&gt;Day 1&lt;/TD&gt;&lt;TD&gt;Height&lt;/TD&gt;&lt;TD&gt;180&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1002&lt;/TD&gt;&lt;TD&gt;Day 1&lt;/TD&gt;&lt;TD&gt;Weight&lt;/TD&gt;&lt;TD&gt;95&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to get Height and Weight per visit and get them multiple times if they are different as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID 1001 taking the non missing value for height. for weight taking non missng value but the weights are different on screen and day1 visits so we get 3 records.&lt;/P&gt;&lt;P&gt;ID 1002 ,height and weight are same during screen and day 1 so we get two records:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Visit&lt;/TD&gt;&lt;TD&gt;Test&lt;/TD&gt;&lt;TD&gt;res&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;Screen&lt;/TD&gt;&lt;TD&gt;Height&lt;/TD&gt;&lt;TD&gt;170&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;Screen&lt;/TD&gt;&lt;TD&gt;Weight&lt;/TD&gt;&lt;TD&gt;82&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;Day 1&lt;/TD&gt;&lt;TD&gt;Weight&lt;/TD&gt;&lt;TD&gt;89&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1002&lt;/TD&gt;&lt;TD&gt;Screen&lt;/TD&gt;&lt;TD&gt;Height&lt;/TD&gt;&lt;TD&gt;180&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1002&lt;/TD&gt;&lt;TD&gt;Screen&lt;/TD&gt;&lt;TD&gt;Weight&lt;/TD&gt;&lt;TD&gt;95&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 30 Oct 2019 16:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600443#M173566</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2019-10-30T16:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600445#M173567</link>
      <description>&lt;P&gt;I am not sure I understand what you are asking for. But it looks like a simple PROC SORT with NODUPKEY .&amp;nbsp; Looks like you want to eliminate the missing values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=want nodupkey;
  where not missing(res);
  by _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 16:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600445#M173567</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-30T16:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600449#M173568</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm='09'x dsd truncover;
input ID $ Visit $ Test$ res;
datalines;
1001	Screen	Height	170
1001	Screen	Weight	82
1001	Screen	Height	 
1001	Screen	Weight	82
1001	Day 1	Height	170
1001	Day 1	Weight	89
1001	Day 1	Height	170
1001	Day 1	Weight	 
1002	Screen	Height	180
1002	Screen	Weight	95
1002	Day 1	Height	180
1002	Day 1	Weight	95
;

proc sort
  data=have (where=(res ne .))
  out=int
;
by id test res;
run;

data want;
set int;
by id test res;
if first.res;
run;

proc sort data=want;
by id descending visit test;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt; ID     Visit      Test     res

1001    Screen    Height    170
1001    Screen    Weight     82
1001    Day 1     Weight     89
1002    Screen    Height    180
1002    Screen    Weight     95
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS by now (almost 800 posts), you should know where to put questions; you're not a "New User" anymore. It should also be an easy exercise for you to post example data in a data step with datalines, so we don't have to do that extra work. It's not rocket science, and it won't make your head explode or cause you to go blind. Promised.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 16:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600449#M173568</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-30T16:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600450#M173569</link>
      <description>&lt;P&gt;PS I moved the question to the correct community.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 16:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600450#M173569</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-30T16:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600453#M173572</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards missover;
input ID	(Visit	Test) (&amp;amp; $10.)	res;
cards;
1001	Screen	Height	170
1001	Screen	Weight	82
1001	Screen	Height	 
1001	Screen	Weight	82
1001	Day 1	Height	170
1001	Day 1	Weight	89
1001	Day 1	Height	170
1001	Day 1	Weight	 
1002	Screen	Height	180
1002	Screen	Weight	95
1002	Day 1	Height	180
1002	Day 1	Weight	95
;


data want ;
if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("id","test","res") ;
   h.definedata ("id","test","res") ;
   h.definedone () ;
end;
set have;
where res&amp;gt;.;
if h.check() ne 0;
 rc=h.add();
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;&amp;nbsp; A best time to recommend a solution beautifully demonstrated by geniuses&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13569"&gt;@DonH&lt;/a&gt;&amp;nbsp; in their book.&lt;/P&gt;
&lt;DIV class="text parbase section"&gt;
&lt;DIV class=""&gt;
&lt;H3&gt;Data Management Solutions Using SAS&lt;SUP&gt;®&lt;/SUP&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Hash Table Operations: A Business Intelligence Case Study&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/H3&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="text parbase section"&gt;
&lt;DIV class=""&gt;
&lt;P&gt;&lt;SPAN class="xsmall-txt-light"&gt;By&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://support.sas.com/en/books/authors/paul-dorfman.html" target="_blank" rel="noopener"&gt;Paul Dorfman&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://support.sas.com/en/books/authors/don-henderson.html" target="_blank" rel="noopener"&gt;Don Henderson&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="xsmall-txt-light"&gt;I plagiarized their solution but why not. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 30 Oct 2019 16:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600453#M173572</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-30T16:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600461#M173573</link>
      <description>&lt;P&gt;The previous would needlessly consume memory to accomodate the entire distinct values of the entire table, and if that's a concern , by group processing helps memory footprint to equivalent only to the largest by group. So improving the previous to--&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards missover;
input ID	(Visit	Test) (&amp;amp; $10.)	res;
cards;
1001	Screen	Height	170
1001	Screen	Weight	82
1001	Screen	Height	 
1001	Screen	Weight	82
1001	Day 1	Height	170
1001	Day 1	Weight	89
1001	Day 1	Height	170
1001	Day 1	Weight	 
1002	Screen	Height	180
1002	Screen	Weight	95
1002	Day 1	Height	180
1002	Day 1	Weight	95
;

data want;
if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("id","test","res") ;
   h.definedata ("id","test","res") ;
   h.definedone () ;
end;
 do until(last.id);
  set have;
  by id;
  where res&amp;gt;.;
  if h.check()=0 then continue;
  rc=h.add();
  output;
 end;
 h.clear();
 drop rc;
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>Wed, 30 Oct 2019 17:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600461#M173573</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-30T17:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600473#M173579</link>
      <description>&lt;P&gt;And the traditional SORT and NODUPKEY as suggested by Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data =have out=want nodupkey;
by id test res;
where res&amp;gt;.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Oct 2019 17:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600473#M173579</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-30T17:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600493#M173593</link>
      <description>Part of the point of the book was to provide source material that could be plagiarized.</description>
      <pubDate>Wed, 30 Oct 2019 18:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600493#M173593</guid>
      <dc:creator>DonH</dc:creator>
      <dc:date>2019-10-30T18:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600508#M173601</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Please feel free to keep plagiarizing ;).&amp;nbsp;Many thanks for the plug!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A little note, if I may: Here you can call the ADD method &lt;EM&gt;unassigned&lt;/EM&gt; (i.e. without coding rc=) because due to the subsetting IF logic, it is always successful - the method is called only when the key is not in the table, and so there's no risk of getting a method call error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 19:24:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-records/m-p/600508#M173601</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-30T19:24:10Z</dc:date>
    </item>
  </channel>
</rss>

