<?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: Create new binary var of first occurrence over multiple rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-binary-var-of-first-occurrence-over-multiple-rows/m-p/516714#M139593</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input ID date Ind;
cards;
1 1801 0
1 1802 0
1 1803 1
1 1804 1
1 1805 0
1 1806 1
2 1801 0
2 1802 1
2 1803 1
2 1804 1
2 1805 1
2 1806 1
;
run;

proc sql;
create table want as
select *,(min(date)=date)*(ind=1) as new
from have
group by id,ind
order by id,date;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Nov 2018 15:04:55 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-11-28T15:04:55Z</dc:date>
    <item>
      <title>Create new binary var of first occurrence over multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-binary-var-of-first-occurrence-over-multiple-rows/m-p/516599#M139544</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a raw data that contain 6 observations &amp;nbsp;for each customer &amp;nbsp;(during follow up period of 6 months).&lt;/P&gt;
&lt;P&gt;For each customer there are 3 fields: ID, month, Ind&lt;/P&gt;
&lt;P&gt;Ind is &amp;nbsp;a binary variable that get value 1 if customer in fail status and 0 otherwise.&lt;/P&gt;
&lt;P&gt;For all customers the value of var "ind" in first month is 0 (customer start is status with no failure)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The task is to create a new binary variable that will receive value 1 in first position where &amp;nbsp;customer is in failure&lt;/P&gt;
&lt;P&gt;Expected values for customer1 are:&lt;/P&gt;
&lt;P&gt;1 1801 0 0&lt;BR /&gt;1 1802 0 0&lt;BR /&gt;1 1803 1 1&lt;BR /&gt;1 1804 1 0&lt;BR /&gt;1 1805 0 0&lt;BR /&gt;1 1806 1 0 &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Expected values for customer2 are:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2 1801 0 0&lt;BR /&gt;2 1802 1 1&lt;BR /&gt;2 1803 1 0&lt;BR /&gt;2 1804 1 0&lt;BR /&gt;2 1805 1 0&lt;BR /&gt;2 1806 1 0&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can anyone suggest a code that create the new field?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data raw_tbl;
input ID date  Ind;
cards;
1 1801 0
1 1802 0
1 1803 1
1 1804 1
1 1805 0
1 1806 1
2 1801 0
2 1802 1
2 1803 1
2 1804 1
2 1805 1
2 1806 1
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 08:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-binary-var-of-first-occurrence-over-multiple-rows/m-p/516599#M139544</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-11-28T08:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create new binary var of first occurrence over multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-binary-var-of-first-occurrence-over-multiple-rows/m-p/516610#M139547</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data raw_tbl;
input ID date Ind;
cards;
1 1801 0
1 1802 0
1 1803 1
1 1804 1
1 1805 0
1 1806 1
2 1801 0
2 1802 1
2 1803 1
2 1804 1
2 1805 1
2 1806 1
;
run;

data want;
set raw_tbl;
by ID;
retain found;
if first.id then found=0;
flag=0;
if Ind ne 0 and found=0 then do;
flag=Ind;
found=1;
end;
drop found;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 10:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-binary-var-of-first-occurrence-over-multiple-rows/m-p/516610#M139547</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-11-28T10:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create new binary var of first occurrence over multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-binary-var-of-first-occurrence-over-multiple-rows/m-p/516714#M139593</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input ID date Ind;
cards;
1 1801 0
1 1802 0
1 1803 1
1 1804 1
1 1805 0
1 1806 1
2 1801 0
2 1802 1
2 1803 1
2 1804 1
2 1805 1
2 1806 1
;
run;

proc sql;
create table want as
select *,(min(date)=date)*(ind=1) as new
from have
group by id,ind
order by id,date;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 15:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-binary-var-of-first-occurrence-over-multiple-rows/m-p/516714#M139593</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-28T15:04:55Z</dc:date>
    </item>
  </channel>
</rss>

