<?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 Retain Flag=1 with ID number in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55056#M15305</link>
    <description>I learned it a year ago at my SAS Base course, but right now, I don't remember anymore... If anyone could help me?&lt;BR /&gt;
&lt;BR /&gt;
I've got a dataset with ID numbers, accompanied by dates (so several ID numbers are the same). Only the first of some ID numbers is flagged with FLAG=1. Now I want all the flagged numbers to have a FLAG=1 for all of them. See below a sample:&lt;BR /&gt;
&lt;BR /&gt;
ID  Date    Flag&lt;BR /&gt;
1     01-01-2008 1&lt;BR /&gt;
1     03-01-2008 0  &lt;BR /&gt;
1     05-01-2008 0&lt;BR /&gt;
2     06-04-2008 0&lt;BR /&gt;
2     10-04-2008 0&lt;BR /&gt;
3     01-01-2008 1&lt;BR /&gt;
3     01-02-2008 0&lt;BR /&gt;
3     01-08-2008 0&lt;BR /&gt;
4     01-01-2008 0&lt;BR /&gt;
5     11-01-2008 0&lt;BR /&gt;
5     12-01-2008 0&lt;BR /&gt;
&lt;BR /&gt;
So I want for ID 1 and 3 a Flag=1 for all their presences.&lt;BR /&gt;
&lt;BR /&gt;
I tried something like:&lt;BR /&gt;
&lt;BR /&gt;
if first.id then do;&lt;BR /&gt;
retain FLAG;&lt;BR /&gt;
if last.id then do;&lt;BR /&gt;
FLAG=1;end;end;&lt;BR /&gt;
&lt;BR /&gt;
But this doesn't work. Anyone an idea? Thanks in advance!&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Wouter

Message was edited by: Wouter</description>
    <pubDate>Wed, 15 Jul 2009 19:07:38 GMT</pubDate>
    <dc:creator>Wouter</dc:creator>
    <dc:date>2009-07-15T19:07:38Z</dc:date>
    <item>
      <title>Retain Flag=1 with ID number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55056#M15305</link>
      <description>I learned it a year ago at my SAS Base course, but right now, I don't remember anymore... If anyone could help me?&lt;BR /&gt;
&lt;BR /&gt;
I've got a dataset with ID numbers, accompanied by dates (so several ID numbers are the same). Only the first of some ID numbers is flagged with FLAG=1. Now I want all the flagged numbers to have a FLAG=1 for all of them. See below a sample:&lt;BR /&gt;
&lt;BR /&gt;
ID  Date    Flag&lt;BR /&gt;
1     01-01-2008 1&lt;BR /&gt;
1     03-01-2008 0  &lt;BR /&gt;
1     05-01-2008 0&lt;BR /&gt;
2     06-04-2008 0&lt;BR /&gt;
2     10-04-2008 0&lt;BR /&gt;
3     01-01-2008 1&lt;BR /&gt;
3     01-02-2008 0&lt;BR /&gt;
3     01-08-2008 0&lt;BR /&gt;
4     01-01-2008 0&lt;BR /&gt;
5     11-01-2008 0&lt;BR /&gt;
5     12-01-2008 0&lt;BR /&gt;
&lt;BR /&gt;
So I want for ID 1 and 3 a Flag=1 for all their presences.&lt;BR /&gt;
&lt;BR /&gt;
I tried something like:&lt;BR /&gt;
&lt;BR /&gt;
if first.id then do;&lt;BR /&gt;
retain FLAG;&lt;BR /&gt;
if last.id then do;&lt;BR /&gt;
FLAG=1;end;end;&lt;BR /&gt;
&lt;BR /&gt;
But this doesn't work. Anyone an idea? Thanks in advance!&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Wouter

Message was edited by: Wouter</description>
      <pubDate>Wed, 15 Jul 2009 19:07:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55056#M15305</guid>
      <dc:creator>Wouter</dc:creator>
      <dc:date>2009-07-15T19:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Flag=1 with ID number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55057#M15306</link>
      <description>The RETAIN statement need not be coded within the DO/END, it is interpreted at compilation.  Also, if you are missing a BY statement, then you would see pertinent diagnostic messages in your SAS log about UNINITIALIZED.  You will want reset the variable back to 0 or a SAS missing_value, I expect with each new FIRST.ID condition, correct?&lt;BR /&gt;
&lt;BR /&gt;
Suggest you add:&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG _ALL_;&lt;BR /&gt;
&lt;BR /&gt;
to help debug your DATA step and the program.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 15 Jul 2009 19:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55057#M15306</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-15T19:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Flag=1 with ID number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55058#M15307</link>
      <description>I believe you'll need to create an auxiliary variable for the RETAIN statement, which you can just drop.&lt;BR /&gt;
&lt;BR /&gt;
Try something like this:&lt;BR /&gt;
&lt;BR /&gt;
data TEST;&lt;BR /&gt;
&lt;BR /&gt;
retain tmp_flag;&lt;BR /&gt;
&lt;BR /&gt;
set test; by id;&lt;BR /&gt;
&lt;BR /&gt;
if first.id then do;&lt;BR /&gt;
	tmp_flag = flag;&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
flag = tmp_flag;&lt;BR /&gt;
&lt;BR /&gt;
drop tmp_flag;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 15 Jul 2009 19:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55058#M15307</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-15T19:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Flag=1 with ID number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55059#M15308</link>
      <description>Thanks for your response!</description>
      <pubDate>Wed, 15 Jul 2009 21:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55059#M15308</guid>
      <dc:creator>Wouter</dc:creator>
      <dc:date>2009-07-15T21:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Flag=1 with ID number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55060#M15309</link>
      <description>Well perfect, this works great!! Thanks!! (got to renew my courses...)</description>
      <pubDate>Wed, 15 Jul 2009 21:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55060#M15309</guid>
      <dc:creator>Wouter</dc:creator>
      <dc:date>2009-07-15T21:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Flag=1 with ID number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55061#M15310</link>
      <description>Why can't you try this&lt;BR /&gt;
&lt;BR /&gt;
data test1;&lt;BR /&gt;
set test;&lt;BR /&gt;
if id ne " " then flag=1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
hope i understood u r qns properly</description>
      <pubDate>Thu, 16 Jul 2009 15:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55061#M15310</guid>
      <dc:creator>ssas</dc:creator>
      <dc:date>2009-07-16T15:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Flag=1 with ID number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55062#M15311</link>
      <description>Because you want to propagate a flag value of 0 if the first record (for the given ID) has a flag of 0.</description>
      <pubDate>Thu, 16 Jul 2009 15:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-Flag-1-with-ID-number/m-p/55062#M15311</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-16T15:54:21Z</dc:date>
    </item>
  </channel>
</rss>

