<?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: SAS query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413639#M101267</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
Input ID UNID STATUS $;
cards;
110 88100 VALID
111 88100 INVALID
112 99100 VALID
113 99100 INVALID
;
run;
data want;
 merge a a(firstobs=2 keep=unid id rename=(unid=_unid id=INVALID_ID));
 if unid=_unid;
 drop _unid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 15 Nov 2017 12:58:52 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-11-15T12:58:52Z</dc:date>
    <item>
      <title>SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413552#M101237</link>
      <description>&lt;P&gt;I have the below dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data A;&lt;BR /&gt;Input ID UNID STATUS $;&lt;BR /&gt;cards;&lt;BR /&gt;110 88100 VALID&lt;BR /&gt;111 88100 INVALID&lt;BR /&gt;112 99100 VALID&lt;BR /&gt;113 99100 INVALID&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May I know how to generate the below output with the above data? Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;UNID &amp;nbsp;&amp;nbsp; STATUS &amp;nbsp;INVALID_ID&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;110&lt;/STRONG&gt; &lt;STRONG&gt;88100&lt;/STRONG&gt; VALID&amp;nbsp;&amp;nbsp;&amp;nbsp; 111&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;112&lt;/STRONG&gt; &lt;STRONG&gt;99100&lt;/STRONG&gt; VALID&amp;nbsp;&amp;nbsp;&amp;nbsp; 113&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 02:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413552#M101237</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2017-11-15T02:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413560#M101242</link>
      <description>&lt;P&gt;This assumes your data set is in sorted order by UNID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by UNID;&lt;/P&gt;
&lt;P&gt;length final_status $ 7;&lt;/P&gt;
&lt;P&gt;retain final_status final_ID invalid_ID;&lt;/P&gt;
&lt;P&gt;if first.UNID then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;final_status=' ' ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;final_ID = .;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;invalid_ID = .;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if status='VALID' then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;final_ID = ID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;final_status = 'VALID';&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else invalid_ID = ID;&lt;/P&gt;
&lt;P&gt;if last.UNID;&lt;/P&gt;
&lt;P&gt;if final_status = ' ' then final_status = 'INVALID';&lt;/P&gt;
&lt;P&gt;keep final_ID UNID final_STATUS INVALID_ID;&lt;/P&gt;
&lt;P&gt;rename final_ID=ID final_status=STATUS;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested, so it may need to be tweaked.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 04:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413560#M101242</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-15T04:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413561#M101243</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you just want to merge the dataset with itself?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  merge a (keep=id unid status where=(status='VALID'))
        a (keep=id unid status rename=(id=INVALID_ID status=xx) where=(xx='INVALID'))
  ;
  by unid ;
  drop xx ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Nov 2017 04:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413561#M101243</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-15T04:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413571#M101250</link>
      <description>&lt;P&gt;If your data realy is as simple as in your example, i.e. a sequence of valid-invalid entries, a simple transposition might be enough:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc transpose data=a out=b(drop=_name_ where=(status="VALID"));
by unid;
id status;
copy status;
var id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Nov 2017 06:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413571#M101250</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-11-15T06:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413639#M101267</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
Input ID UNID STATUS $;
cards;
110 88100 VALID
111 88100 INVALID
112 99100 VALID
113 99100 INVALID
;
run;
data want;
 merge a a(firstobs=2 keep=unid id rename=(unid=_unid id=INVALID_ID));
 if unid=_unid;
 drop _unid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Nov 2017 12:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413639#M101267</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-15T12:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413725#M101293</link>
      <description>&lt;P&gt;What do you want&amp;nbsp;when you have multiple Valid records for a given UNID?&lt;/P&gt;
&lt;P&gt;What do you want when you have multiple Invalid records for a given UNID?&lt;/P&gt;
&lt;P&gt;What if there are NO Valid records but there are&amp;nbsp;Invalid record(s)&amp;nbsp;for a given UNID?&lt;/P&gt;
&lt;P&gt;What if there are NO Invalid records but there are&amp;nbsp;Valid record(s)&amp;nbsp;for a given UNID?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really need to answer these a different approaches may resolve some cases but not others.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 16:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/413725#M101293</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-15T16:25:06Z</dc:date>
    </item>
  </channel>
</rss>

