<?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: Manipulate long data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364375#M86426</link>
    <description>&lt;P&gt;Below query should work.&lt;/P&gt;
&lt;PRE&gt;data have;
input ID    Type $;
datalines;
1      4045
1      0014
1      0100
1      0038
2      0014
2      4045 
2      0006
;

proc sql;
create table want as 
select distinct id, type2 from 
(select id,
case when id  in (select id from have a
where trim(Type) ='0100') then 'procedure did not run' else Type end as Type2 
from have)a;
quit;
&lt;/PRE&gt;</description>
    <pubDate>Mon, 05 Jun 2017 21:07:18 GMT</pubDate>
    <dc:creator>kiranv_</dc:creator>
    <dc:date>2017-06-05T21:07:18Z</dc:date>
    <item>
      <title>Manipulate long data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364367#M86422</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is how my data looks:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID &amp;nbsp; &amp;nbsp;Type&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;4045&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0014&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0100&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0038&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;0014&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;4045&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;0006&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to identify all IDs where Type=0100 (this means the procedure did not run so the other types aren't accurate), while keeping the data the same when there is no Type 0100 for the ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So in this case my data would look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID &amp;nbsp; &amp;nbsp;Type2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;procedure didn't run&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;0014&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;4045&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;0006&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I do this? I'm thinking it may have to do with using first and last.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 20:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364367#M86422</guid>
      <dc:creator>amanda_cr</dc:creator>
      <dc:date>2017-06-05T20:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate long data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364373#M86425</link>
      <description>&lt;P&gt;Here's one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;length&amp;nbsp;type $ 20;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if type = '0100' then situation = "procedure didn't run";&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if situation = ' ' then output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if situation = "procedure didn't run" then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; type = situation;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop situation;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that your data set is sorted by ID.&amp;nbsp; The top loop examines observations for one ID, to see if "0100" is found.&amp;nbsp; The second loop re-reads the same observations, possibly outputting them.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 20:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364373#M86425</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-05T20:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate long data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364375#M86426</link>
      <description>&lt;P&gt;Below query should work.&lt;/P&gt;
&lt;PRE&gt;data have;
input ID    Type $;
datalines;
1      4045
1      0014
1      0100
1      0038
2      0014
2      4045 
2      0006
;

proc sql;
create table want as 
select distinct id, type2 from 
(select id,
case when id  in (select id from have a
where trim(Type) ='0100') then 'procedure did not run' else Type end as Type2 
from have)a;
quit;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Jun 2017 21:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364375#M86426</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-05T21:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate long data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364481#M86454</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/121331"&gt;@amanda_cr&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;The simples solution I can think of is this:&lt;/P&gt;&lt;PRE&gt;data want;
  merge have have(where=(type='0100') in=failed);
  by ID;
  if failed then do; 
    if first.ID;
    type='Procedure did not run';
    end;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jun 2017 06:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364481#M86454</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-06-06T06:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate long data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364595#M86483</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 14:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364595#M86483</guid>
      <dc:creator>amanda_cr</dc:creator>
      <dc:date>2017-06-06T14:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate long data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364596#M86484</link>
      <description>&lt;P&gt;Thanks everyone! All three solutions worked. I went with the SQL once because I prefer SQL.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 14:40:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulate-long-data/m-p/364596#M86484</guid>
      <dc:creator>amanda_cr</dc:creator>
      <dc:date>2017-06-06T14:40:01Z</dc:date>
    </item>
  </channel>
</rss>

