<?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 for multiple observations per subject in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279903#M56483</link>
    <description>&lt;P&gt;Great, thanks, I'll give this a try.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jun 2016 04:00:25 GMT</pubDate>
    <dc:creator>TJ87</dc:creator>
    <dc:date>2016-06-24T04:00:25Z</dc:date>
    <item>
      <title>Subset for multiple observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279875#M56462</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data looks something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; A B&amp;nbsp; C D&amp;nbsp; E&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp; a&amp;nbsp; a&amp;nbsp; b&amp;nbsp; a&amp;nbsp; a&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp; a&amp;nbsp; b&amp;nbsp; b&amp;nbsp; b&amp;nbsp; b&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp; c&amp;nbsp; c&amp;nbsp; b&amp;nbsp; a&amp;nbsp; a &amp;nbsp;&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp; b&amp;nbsp; c&amp;nbsp; c&amp;nbsp; c&amp;nbsp; a&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to output where the observations differ for any given column (A-E):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID B D E&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; a a&amp;nbsp; a&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; b b&amp;nbsp; b&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID A C D&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; c&amp;nbsp; b&amp;nbsp; a&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; b&amp;nbsp; c&amp;nbsp; c&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could someone please suggest some code for this? Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 23:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279875#M56462</guid>
      <dc:creator>TJ87</dc:creator>
      <dc:date>2016-06-23T23:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: Subset for multiple observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279891#M56474</link>
      <description>&lt;P&gt;Do you simply want to know which variables differ for each ID, or create one&amp;nbsp;new&amp;nbsp;dataset for each ID ?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 02:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279891#M56474</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-24T02:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Subset for multiple observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279895#M56476</link>
      <description>&lt;P&gt;Assuming I understand what you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID  (A B  C D  E) ($);
cards;
1   a  a  b  a  a
1   a  b  b  b  b
2   c  c  b  a  a  
2   b  c  c  c  a
;
run;

proc sql;
create table temp as
 select id,
        (count(distinct A)=count(*)) as A,
        (count(distinct B)=count(*)) as B,
        (count(distinct C)=count(*)) as C,
        (count(distinct D)=count(*)) as D,
        (count(distinct E)=count(*)) as E
  from have
   group by id;
quit;
proc transpose data=temp out=key(where=(col1=1));
by id;
run;
data _null_;
 set key;
 by id;
 if first.id then call execute(cats('data want',id,';set have;if id=',id,';keep id '));
 call execute(_name_);
 if last.id then call execute(';run;');
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2016 03:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279895#M56476</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-24T03:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Subset for multiple observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279897#M56477</link>
      <description>&lt;P&gt;I'd just like to know which variables differ for each ID. Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 03:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279897#M56477</guid>
      <dc:creator>TJ87</dc:creator>
      <dc:date>2016-06-24T03:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Subset for multiple observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279898#M56478</link>
      <description>&lt;P&gt;Wow, thank you. I'll give this a try. Can you suggest a shorthand notation for the explanatory (A-E) variables? I have about 100. Thanks. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 03:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279898#M56478</guid>
      <dc:creator>TJ87</dc:creator>
      <dc:date>2016-06-24T03:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Subset for multiple observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279899#M56479</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID  (A B  C D  E) ($);
cards;
1   a  a  b  a  a
1   a  b  b  b  b
2   c  c  b  a  a  
2   b  c  c  c  a
;

data temp;
length var $12;
set have;
array x $ _character_;
do i = 2 to dim(x);
    var = vname(x{i});
    value = x{i};
    output;
    end;
keep id var value;
run;

proc sql;
create table want as
select id, var
from temp
group by id, var
having count(distinct value) &amp;gt; 1;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2016 03:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279899#M56479</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-24T03:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Subset for multiple observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279900#M56480</link>
      <description>&lt;P&gt;Sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID  (A B  C D  E) ($);
cards;
1   a  a  b  a  a
1   a  b  b  b  b
2   c  c  b  a  a  
2   b  c  c  c  a
;
run;

proc transpose data=have(obs=0) out=vnames;
var _all_;
run;

proc sql noprint;
select catx(' ','(count(distinct',_name_,')=count(*)) as',_name_)
       into : list separated by ','
 from vnames
  where upcase(_name_) ne 'ID';

create table temp as
 select id,&amp;amp;list
  from have
   group by id;
quit;
proc transpose data=temp out=key(where=(col1=1));
by id;
run;
data _null_;
 set key;
 by id;
 if first.id then call execute(cats('data want',id,';set have;if id=',id,';keep id '));
 call execute(_name_);
 if last.id then call execute(';run;');
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2016 03:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279900#M56480</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-24T03:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Subset for multiple observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279902#M56482</link>
      <description>&lt;P&gt;Wow, thank you very much Keshan.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 03:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279902#M56482</guid>
      <dc:creator>TJ87</dc:creator>
      <dc:date>2016-06-24T03:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Subset for multiple observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279903#M56483</link>
      <description>&lt;P&gt;Great, thanks, I'll give this a try.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 04:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/279903#M56483</guid>
      <dc:creator>TJ87</dc:creator>
      <dc:date>2016-06-24T04:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Subset for multiple observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/280044#M56531</link>
      <description>&lt;P&gt;This works, too! Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 18:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-for-multiple-observations-per-subject/m-p/280044#M56531</guid>
      <dc:creator>TJ87</dc:creator>
      <dc:date>2016-06-24T18:17:15Z</dc:date>
    </item>
  </channel>
</rss>

