<?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 DO Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520059#M140972</link>
    <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS 9.4 and have a programming question&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking at encounters (each encounter has multiple rows but not of the same&amp;nbsp;number of rows&amp;nbsp;throughout the dataset eg one encounter may have 10 rows and another have only 2) and I want to see if a code 1 and a code 2 is present with the multiple encounters. I have set up the dataset with a retain statement such that each encounter is label 1 ,2 ,3 etc. Is it possible to achieve this in SAS? Thank you for the help!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Dec 2018 17:20:23 GMT</pubDate>
    <dc:creator>GS2</dc:creator>
    <dc:date>2018-12-10T17:20:23Z</dc:date>
    <item>
      <title>DO Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520059#M140972</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS 9.4 and have a programming question&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking at encounters (each encounter has multiple rows but not of the same&amp;nbsp;number of rows&amp;nbsp;throughout the dataset eg one encounter may have 10 rows and another have only 2) and I want to see if a code 1 and a code 2 is present with the multiple encounters. I have set up the dataset with a retain statement such that each encounter is label 1 ,2 ,3 etc. Is it possible to achieve this in SAS? Thank you for the help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 17:20:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520059#M140972</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2018-12-10T17:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520064#M140976</link>
      <description>&lt;P&gt;Could you do something like this? instead of sashelp.class use your dataset and instead of AGE use the code var, and use 1 and 2 for 14 and 15.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.class;
	where AGE in (14 15);
	table age;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Dec 2018 17:30:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520064#M140976</guid>
      <dc:creator>rbikes</dc:creator>
      <dc:date>2018-12-10T17:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520066#M140978</link>
      <description>&lt;P&gt;I thought about that at first. However, using this method it returns every time there is a 1 or 2 and I want it to only return if their is a 1 and 2.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 17:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520066#M140978</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2018-12-10T17:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520086#M140981</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using SAS 9.4 and have a programming question&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking at encounters (each encounter has multiple rows but not of the same&amp;nbsp;number of rows&amp;nbsp;throughout the dataset eg one encounter may have 10 rows and another have only 2) and I want to see if a code 1 and a code 2 is present with the multiple encounters. I have set up the dataset with a retain statement such that each encounter is label 1 ,2 ,3 etc. Is it possible to achieve this in SAS? Thank you for the help!&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sure would be nice if you can show us a small example. Please use these instructions to provide your small example as a SAS data step:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 18:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520086#M140981</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-10T18:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520094#M140984</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data for demonstration */

data have;
input enc code;
cards;
1 3
1 2
1 2
1 4
2 2
2 4
2 3
2 1
2 5
3 22
3 1
3 1
4 1
4 0
4 2
;

/* Select encounters with both code 1 and code 2 */

data want(drop=_:);
do until(last.enc);
  set have;
  by enc;
  if code=1 then _c1=1;
  else if code=2 then _c2=1;
end;
do until(last.enc);
  set have;
  by enc;
  if _c1 &amp;amp; _c2 then output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't need &lt;EM&gt;all&lt;/EM&gt; observations from the selected encounters, but just their numbers, replace the entire second DO loop by a subsetting IF statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if _c1 &amp;amp; _c2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and change&amp;nbsp;&lt;FONT face="courier new,courier"&gt;drop=_:&lt;/FONT&gt;&amp;nbsp;to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;keep=enc&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 18:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop/m-p/520094#M140984</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-12-10T18:36:49Z</dc:date>
    </item>
  </channel>
</rss>

