<?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: subset dataset if all obs for a variable is not missing for an ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/482048#M124798</link>
    <description>&lt;P&gt;Nice one&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;how did&amp;nbsp; 4 X "' "&amp;nbsp; get to be true&amp;nbsp;nonblanks. Where am i missing the point?&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jul 2018 20:44:55 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-07-27T20:44:55Z</dc:date>
    <item>
      <title>subset dataset if all obs for a variable is not missing for an ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/481984#M124773</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;here is the sample dataset&amp;nbsp;which I want to subset into dataset A and B. In dataset B, keep PINs if all obs for session is blank. If one of the Obs&amp;nbsp;in "Session"&amp;nbsp;for a &amp;nbsp;PIN&amp;nbsp;is not blank then keep all the obs for that PIN in dataset B. Please suggest.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;dataset&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;ID&lt;/TD&gt;&lt;TD&gt;Level&lt;/TD&gt;&lt;TD&gt;Session&lt;/TD&gt;&lt;/TR&gt;&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;/FONT&gt;&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;&lt;FONT color="#000000" face="Calibri" size="3"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Level&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Session&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Z&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;X&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Y&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Z&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Z&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;X&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&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;&lt;FONT color="#000000" face="Calibri" size="3"&gt;dataset A&lt;/FONT&gt;&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;&lt;FONT color="#000000" face="Calibri" size="3"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Level&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Session&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;X&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;X&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Y&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;B&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 27 Jul 2018 18:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/481984#M124773</guid>
      <dc:creator>d0816</dc:creator>
      <dc:date>2018-07-27T18:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: subset dataset if all obs for a variable is not missing for an ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/481987#M124774</link>
      <description>&lt;P&gt;Merge a subset of non-blanks with the entire dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dm 'clear log';
data have;
infile datalines missover;
input id	Level :$1.	Session :$1.;
datalines;
1	Z	 
2	X	 
2	Y	 
2	Z	 
3	Z	 
3	X	 
4	X	A
4	X	 
4	Y	B
run;
data a b;
   merge have (where=(session^=' ') in=anynonblanks)  have;
   by id;
   if anynonblanks then output b;
   else output a;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Jul 2018 19:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/481987#M124774</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-07-27T19:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: subset dataset if all obs for a variable is not missing for an ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/481999#M124781</link>
      <description>This worked in my original dataset. Thank you so much.</description>
      <pubDate>Fri, 27 Jul 2018 19:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/481999#M124781</guid>
      <dc:creator>d0816</dc:creator>
      <dc:date>2018-07-27T19:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: subset dataset if all obs for a variable is not missing for an ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/482048#M124798</link>
      <description>&lt;P&gt;Nice one&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;how did&amp;nbsp; 4 X "' "&amp;nbsp; get to be true&amp;nbsp;nonblanks. Where am i missing the point?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2018 20:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/482048#M124798</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-27T20:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: subset dataset if all obs for a variable is not missing for an ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/482123#M124820</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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two attributes of MERGE being utilized&amp;nbsp;here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Values in the "right" dataset supersede those in the "left", for all common variables.&amp;nbsp;&amp;nbsp; In this case, for id 4 the "left" has&amp;nbsp;the two non-blank observations, in this order: &lt;BR /&gt;&amp;nbsp;&amp;nbsp;1st rec:&amp;nbsp; 4 X A&lt;BR /&gt;&amp;nbsp;&amp;nbsp;2nd rec: &amp;nbsp;4 Y B&lt;BR /&gt;but the "right" dataset has all the ID=4 observations in this order:&lt;BR /&gt;&amp;nbsp; 1st rec:&amp;nbsp;&amp;nbsp;&amp;nbsp; 4 X A&lt;BR /&gt;&amp;nbsp;&amp;nbsp;2nd rec:&amp;nbsp; &amp;nbsp; 4 X&amp;nbsp;blank&lt;BR /&gt;&amp;nbsp;&amp;nbsp;3rd rec:&amp;nbsp; &amp;nbsp; 4 X B&lt;BR /&gt;&lt;BR /&gt;Within a BY group 1st rec matches with first rec, 2nd with 2nd, etc.&amp;nbsp; So the merge results are&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 1st rec:&amp;nbsp;&amp;nbsp; 4 X A&amp;nbsp;&amp;nbsp; is "superseded" by 4 X A&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 2nd rec:&amp;nbsp; 4 Y B&amp;nbsp; is "superseded" by 4 X blank&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 3rd rec:&amp;nbsp;&amp;nbsp; 4 Y B (see below) is "supersede" by 4 X B&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;When either the left or right merged dataset is shorter within a BY group, then it's last observation is repeatedly matched to all the "excess" observations of the dataset with the longer BY group.&amp;nbsp; That's why&amp;nbsp;in&amp;nbsp;my example of the 3rd rec above you see "4 Y B" propagated.&amp;nbsp;&amp;nbsp; And the "in=" parameter is also propagated.&amp;nbsp; So the "excess" observation goes to the same destination as all the other ID=4 obs.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;In fact, if you merge more than two datasets, then the principle is extended: for any common variable in multiple datasets, the rightmost value prevails, assuming the variable is of the same type (numeric or character) for all datasets.&amp;nbsp; If a variable is of both types, the merge fails.&amp;nbsp; In the case of other attributes (length, label, format), they&amp;nbsp;are inherited from the leftmost dataset, since that's the first encounter the sas compiler has with the variable.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;values&amp;nbsp; supersede&lt;/P&gt;
&lt;P&gt;What does MERGE X Y; BY ID; do when an ID group has fewer observations in (say)&amp;nbsp; X than in Y.&amp;nbsp;&amp;nbsp; It propagates the last observation in X to be associated with the "excess" observations in Y.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When an ID group is being MERGEd, and&amp;nbsp; there are no an equal number of observations in the "left" and "right" datasets,&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jul 2018 00:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/482123#M124820</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-07-28T00:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: subset dataset if all obs for a variable is not missing for an ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/482135#M124824</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;Thank you so much for explaining at length. I really appreciate the privilege of receiving your time and knowledge.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jul 2018 02:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-if-all-obs-for-a-variable-is-not-missing-for-an/m-p/482135#M124824</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-28T02:38:24Z</dc:date>
    </item>
  </channel>
</rss>

