<?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: First occurrence of a non 0 number per group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557654#M155485</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/228108"&gt;@rosegarden81&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;

infile datalines dsd truncover;

input Patient 2. Class 2. Indicator 5.;

datalines;
1 1 0
1 2 0
1 2 1
1 2 1
1 2 9
1 3 0
1 3 0
1 3 2
1 3 8
2 1 0
2 1 1
2 2 0
2 2 5
2 2 7
2 3 1
;

data want;
do _n_=1 by 1 until(last.class);
set have;
by patient class;
if  indicator and not k  then k=_n_;
end;
do _n_=1 by 1 until(last.class);
set have;
by patient class;
if  _n_&amp;lt;=k  then output;
end;
drop k;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 10 May 2019 00:08:21 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-05-10T00:08:21Z</dc:date>
    <item>
      <title>First occurrence of a non 0 number per group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557634#M155473</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I am trying to create this class_wanted variable. Which is 1 for first non zero value of Indicator (per patient per class).&lt;/P&gt;&lt;P&gt;The code I am using (as seen below where you see Class_Getting gets generated) is doing different than what I was hoping for..I was trying to generate something like Class_Wanted where it is all just 1's or any other constant number representing the yellow groups..&lt;/P&gt;&lt;P&gt;Any advice is greatly appreciated!..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;set old;&lt;/P&gt;&lt;P&gt;by patient class;&lt;/P&gt;&lt;P&gt;if first.class then Class_Getting = Indicator;&lt;/P&gt;&lt;P&gt;Class_Getting + Indicator;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 542px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29393iCC2528B6A9DDFD3A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 22:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557634#M155473</guid>
      <dc:creator>rosegarden81</dc:creator>
      <dc:date>2019-05-09T22:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: First occurrence of a non 0 number per group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557640#M155479</link>
      <description>&lt;P&gt;Provide a data step instead of a picture of data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &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; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The text of your rule does not match your picture. You say "1 for first non zero value of Indicator&amp;nbsp;" but the first yellow line has indicator =0, and multiple others where indicator=0 highlighted. And I don't see why the Patient=1 Class=3 first indicator=0 is highlighted but not the Patient=1 class=1 first 0. So please work on the process description a bit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe this gets you started:&lt;/P&gt;
&lt;PRE&gt;data new;
   set old;
   by patient class;
   retain firstflag;
   if first.class then do;
      Class_Getting = Indicator;
      class_wanted=1;
      firstflag=0;
   end;
   if firstflag=0 and indicator ne 0 then do;
      firstflag=1;
      class_wanted=1;
   end;
   Class_Getting + Indicator;
run;&lt;/PRE&gt;
&lt;P&gt;The retain statement says to keep the value of a variable across records.&lt;/P&gt;
&lt;P&gt;If this works you can DROP FIRSTFLAG; to remove it from the data.&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 23:08:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557640#M155479</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-09T23:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: First occurrence of a non 0 number per group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557647#M155481</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;My apologies I couldn't explain properly. So I was trying to select all rows up till first non zero indicator per patient per class which includes any zero indicator before the first non zero occurrence.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for patient = 1 and Class = 2, I want to select its first row and the next row (as the next row indicator = 1).&lt;/P&gt;&lt;P&gt;So the yellow highlight was showing the same.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For patient 1 class 3, the first non zero indicator occurs in third instance of that group so I want to select the first three rows of that group.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My apologies for the confusion.&lt;/P&gt;&lt;P&gt;I have included the data step after referencing the link you mentioned below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;infile datalines dsd truncover;&lt;/P&gt;&lt;P&gt;input Patient 2. Class 2. Indicator 5.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 1 0&lt;BR /&gt;1 2 0&lt;BR /&gt;1 2 1&lt;BR /&gt;1 2 1&lt;BR /&gt;1 2 9&lt;BR /&gt;1 3 0&lt;BR /&gt;1 3 0&lt;BR /&gt;1 3 2&lt;BR /&gt;1 3 8&lt;BR /&gt;2 1 0&lt;BR /&gt;2 1 1&lt;BR /&gt;2 2 0&lt;BR /&gt;2 2 5&lt;BR /&gt;2 2 7&lt;BR /&gt;2 3 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 23:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557647#M155481</guid>
      <dc:creator>rosegarden81</dc:creator>
      <dc:date>2019-05-09T23:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: First occurrence of a non 0 number per group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557654#M155485</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/228108"&gt;@rosegarden81&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;

infile datalines dsd truncover;

input Patient 2. Class 2. Indicator 5.;

datalines;
1 1 0
1 2 0
1 2 1
1 2 1
1 2 9
1 3 0
1 3 0
1 3 2
1 3 8
2 1 0
2 1 1
2 2 0
2 2 5
2 2 7
2 3 1
;

data want;
do _n_=1 by 1 until(last.class);
set have;
by patient class;
if  indicator and not k  then k=_n_;
end;
do _n_=1 by 1 until(last.class);
set have;
by patient class;
if  _n_&amp;lt;=k  then output;
end;
drop k;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 May 2019 00:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557654#M155485</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-10T00:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: First occurrence of a non 0 number per group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557779#M155544</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile datalines dsd truncover;
input Patient 2. Class 2. Indicator 5.;
datalines;
1 1 0
1 2 0
1 2 1
1 2 1
1 2 9
1 3 0
1 3 0
1 3 2
1 3 8
2 1 0
2 1 1
2 2 0
2 2 5
2 2 7
2 3 1
;

data want;
 set have;
 by Patient Class;
 retain want 1 found .;
 if first.class then do;want=1;found=.;end;
 if found then want=.;
 if Indicator ne 0 and not found then found=1;
 drop found;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 May 2019 14:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557779#M155544</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-05-10T14:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: First occurrence of a non 0 number per group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557871#M155590</link>
      <description>Thank you so much! This is also very very helpful..However, this was filtering the data instead of flagging...but I am learning new concepts as time goes so that is cool..</description>
      <pubDate>Fri, 10 May 2019 16:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557871#M155590</guid>
      <dc:creator>rosegarden81</dc:creator>
      <dc:date>2019-05-10T16:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: First occurrence of a non 0 number per group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557872#M155591</link>
      <description>Thank you so much! This is very helpful indeed!</description>
      <pubDate>Fri, 10 May 2019 16:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-occurrence-of-a-non-0-number-per-group/m-p/557872#M155591</guid>
      <dc:creator>rosegarden81</dc:creator>
      <dc:date>2019-05-10T16:48:39Z</dc:date>
    </item>
  </channel>
</rss>

