<?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: Set flag for each record based on first obs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613569#M179203</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=",";
input ID DATE:MONYY7. PRINCIPAL;
format DATE monyy7.;
datalines;
1,SEP2019, -10
1,JUL2019, 0
1,AUG2019, 0
2,JAN2019, 0
2,FEB2019, 0
3,JAN2019, 1
3,FEB2019, 0
3,MAR2019, 0
;
run;

data want;
 do until (last.id);
  set have;
  by id;
  if first.ID then remove=principal &amp;lt;=0;
  output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 23 Dec 2019 17:05:45 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-12-23T17:05:45Z</dc:date>
    <item>
      <title>Set flag for each record based on first obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613563#M179197</link>
      <description>&lt;P&gt;Hi all, I'm pretty sure I have a simple request. If the first.ID and princpal &amp;lt;= 0 then set remove = 1.&lt;/P&gt;
&lt;P&gt;What I have done successfully does this for the first ID but I need it to then apply that remove = 1 to ALL subsequent columns by that ID regardless of those row values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is Have/Want and what I did (which only does the first record). Any help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=",";
input ID DATE:MONYY7. PRINCIPAL;
format DATE monyy7.;
datalines;
1,SEP2019, -10
1,JUL2019, 0
1,AUG2019, 0
2,JAN2019, 0
2,FEB2019, 0
3,JAN2019, 1
3,FEB2019, 0
3,MAR2019, 0
;
run;

data want;
infile datalines delimiter=",";
input ID DATE:MONYY7. PRINCIPAL, remove;
format DATE monyy7.;
datalines;
1,SEP2019, -10,1
1,JUL2019, 0,1
1,AUG2019, 0,1
2,JAN2019, 0,1
2,FEB2019, 0,1
3,JAN2019, 1,0
3,FEB2019, 0,0
3,MAR2019, 0,0
;
run;

data want;
	set have;
	by ID;
	if first.ID and principal &amp;lt;=0 then remove=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Dec 2019 16:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613563#M179197</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-12-23T16:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: Set flag for each record based on first obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613565#M179199</link>
      <description>&lt;P&gt;Hi, Krueger&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;check this code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by id;
  retain remove;
  if first.id then do;
    if PRINCIPAL &amp;lt;= 0 then remove = 1;
    else remove=0;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2019 16:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613565#M179199</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2019-12-23T16:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Set flag for each record based on first obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613566#M179200</link>
      <description>&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by id;
   retain remove;
   if first.id then remove=(principal&amp;lt;0);
run;
&lt;/PRE&gt;
&lt;P&gt;RETAIN tells SAS to keep the value of the variable across the records. SAS will treat true comparisons as 1 and false as 0 so placing the () around the principal &amp;lt; 0 will return 1 or 0 as the value for remove.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2019 17:01:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613566#M179200</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-23T17:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: Set flag for each record based on first obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613567#M179201</link>
      <description>&lt;P&gt;Appreciate the explanation behind this. Very helpful!&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2019 17:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613567#M179201</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-12-23T17:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: Set flag for each record based on first obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613569#M179203</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=",";
input ID DATE:MONYY7. PRINCIPAL;
format DATE monyy7.;
datalines;
1,SEP2019, -10
1,JUL2019, 0
1,AUG2019, 0
2,JAN2019, 0
2,FEB2019, 0
3,JAN2019, 1
3,FEB2019, 0
3,MAR2019, 0
;
run;

data want;
 do until (last.id);
  set have;
  by id;
  if first.ID then remove=principal &amp;lt;=0;
  output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Dec 2019 17:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-flag-for-each-record-based-on-first-obs/m-p/613569#M179203</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-23T17:05:45Z</dc:date>
    </item>
  </channel>
</rss>

