<?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: DO LOOP for summarizing a variable per multiple ID entries in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/DO-LOOP-for-summarizing-a-variable-per-multiple-ID-entries/m-p/250172#M6710</link>
    <description>&lt;P&gt;Process is:&lt;/P&gt;
&lt;P&gt;1. Find values for each ID&lt;/P&gt;
&lt;P&gt;2. Apply to all values of that ID&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This can be done via a merge, DOW loop, SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution below is SQL and does leave a Note in the log so it's up to you to decide if it's efficient. If notes are an issue, I'd suggest doing it in a two step process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.*, max(case when method in ('inj' 'iud') then 1
                  else 0
                  END) as Found
from have as a
group by ID
order by id, visitnum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 15 Feb 2016 20:08:33 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-02-15T20:08:33Z</dc:date>
    <item>
      <title>DO LOOP for summarizing a variable per multiple ID entries</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DO-LOOP-for-summarizing-a-variable-per-multiple-ID-entries/m-p/250155#M6709</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to write an array or do loop maybe to scan all values for an indicator variable and if there is a single "1" then output to a new variable a "1" for ALL observations (rows) for that specific ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wrote this code below to try it, but it just outputs a "1" for the new variable triedhc in the rows where it is true, but not for ALL rows for the htid so I think I need to put it in a do loop or array but my attempts aren't working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; set have; by htid;
triedhc=IFN(method in('T_IUD','T_INJ','T_OCP'),1,0); 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data have;
input ID   visitnum   method  $;
cards;
1      1       inj        
1      2       inj      
1      3       inj
1      4       .
1      5       inj
2      1       nonhormonal
2      2       nonhormonal
2      3       .
3      1       iud
3      2       iud&lt;BR /&gt;3      3       iud&lt;BR /&gt;4      1       nonhormonal     &lt;BR /&gt;4      2       nonhormonal &lt;BR /&gt;4      3       nonhormonal&lt;BR /&gt;4      4       nonhormonal&lt;BR /&gt;
 ;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 20:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DO-LOOP-for-summarizing-a-variable-per-multiple-ID-entries/m-p/250155#M6709</guid>
      <dc:creator>mcdj</dc:creator>
      <dc:date>2016-02-15T20:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP for summarizing a variable per multiple ID entries</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DO-LOOP-for-summarizing-a-variable-per-multiple-ID-entries/m-p/250172#M6710</link>
      <description>&lt;P&gt;Process is:&lt;/P&gt;
&lt;P&gt;1. Find values for each ID&lt;/P&gt;
&lt;P&gt;2. Apply to all values of that ID&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This can be done via a merge, DOW loop, SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution below is SQL and does leave a Note in the log so it's up to you to decide if it's efficient. If notes are an issue, I'd suggest doing it in a two step process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.*, max(case when method in ('inj' 'iud') then 1
                  else 0
                  END) as Found
from have as a
group by ID
order by id, visitnum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Feb 2016 20:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DO-LOOP-for-summarizing-a-variable-per-multiple-ID-entries/m-p/250172#M6710</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-15T20:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP for summarizing a variable per multiple ID entries</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DO-LOOP-for-summarizing-a-variable-per-multiple-ID-entries/m-p/250184#M6711</link>
      <description>&lt;P&gt;thanks, works perfectly. Fine with the note &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 20:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DO-LOOP-for-summarizing-a-variable-per-multiple-ID-entries/m-p/250184#M6711</guid>
      <dc:creator>mcdj</dc:creator>
      <dc:date>2016-02-15T20:44:41Z</dc:date>
    </item>
  </channel>
</rss>

