<?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: Retain statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36354#M9136</link>
    <description>data latest( keep= client sku volume ) ;&lt;BR /&gt;
 * assuming the name of the raw data is CLIENTS ;&lt;BR /&gt;
  set clients( obs= 0 ) ; * getting column definitions ;&lt;BR /&gt;
  do while( not finished ) ;&lt;BR /&gt;
      set clients( rename= ( client= rawC )) end= finished ;&lt;BR /&gt;
      client = coalesce( rawC, client ) ;&lt;BR /&gt;
      output ;&lt;BR /&gt;
   end ;&lt;BR /&gt;
   stop ;&lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
if column CLIENT is character, use function COALESCEC() rather than COALESCE() &lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Peter.C

getting column definitions was intended as comment, prefix with *&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Peter.C</description>
    <pubDate>Tue, 26 May 2009 12:03:20 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2009-05-26T12:03:20Z</dc:date>
    <item>
      <title>Retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36352#M9134</link>
      <description>I'm just starting using SAS...I received a file in his format:&lt;BR /&gt;
&lt;BR /&gt;
Client...SKU....Volume&lt;BR /&gt;
3020....1000.....10&lt;BR /&gt;
...........1001......3&lt;BR /&gt;
............1002..... 7&lt;BR /&gt;
5505.... 2001.....15&lt;BR /&gt;
..... ......1005 .....6&lt;BR /&gt;
............1004.....30&lt;BR /&gt;
&lt;BR /&gt;
I need to complete the blank with the previus value, for exemle, for line2 the client is 3020 too. How could i do it? A friend toldmeto use Retain statement but did not work.&lt;BR /&gt;
&lt;BR /&gt;
I tried this code:&lt;BR /&gt;
&lt;BR /&gt;
Data test;&lt;BR /&gt;
Set test;&lt;BR /&gt;
&lt;BR /&gt;
 Retain Client; &lt;BR /&gt;
If _n_=1 then Client=NEW_CLIENT;&lt;BR /&gt;
      Else do;&lt;BR /&gt;
            If NEW_CLIENT=’’ then NEW CLIENT=CLIENT;&lt;BR /&gt;
            Else Client=NEW_CLIENT;&lt;BR /&gt;
End;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Mon, 25 May 2009 22:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36352#M9134</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-25T22:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36353#M9135</link>
      <description>The _N_ condition is only in effect with the first observation.  You will need to use a sorted input file and use a BY statement with the key variables, and retain the important variable(s) using the IF FIRST.&lt;VARNAME&gt; THEN &lt;LOGIC&gt;;  condition.&lt;BR /&gt;
&lt;BR /&gt;
Check the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website for DATA STEP PROGRAMMING discussion and using a BY statement and the FIRST.&lt;VARNAME&gt;  and LAST.&lt;VARNAME&gt;  conditions for additional details.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/VARNAME&gt;&lt;/VARNAME&gt;&lt;/LOGIC&gt;&lt;/VARNAME&gt;</description>
      <pubDate>Tue, 26 May 2009 00:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36353#M9135</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-26T00:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36354#M9136</link>
      <description>data latest( keep= client sku volume ) ;&lt;BR /&gt;
 * assuming the name of the raw data is CLIENTS ;&lt;BR /&gt;
  set clients( obs= 0 ) ; * getting column definitions ;&lt;BR /&gt;
  do while( not finished ) ;&lt;BR /&gt;
      set clients( rename= ( client= rawC )) end= finished ;&lt;BR /&gt;
      client = coalesce( rawC, client ) ;&lt;BR /&gt;
      output ;&lt;BR /&gt;
   end ;&lt;BR /&gt;
   stop ;&lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
if column CLIENT is character, use function COALESCEC() rather than COALESCE() &lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Peter.C

getting column definitions was intended as comment, prefix with *&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Peter.C</description>
      <pubDate>Tue, 26 May 2009 12:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36354#M9136</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-05-26T12:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36355#M9137</link>
      <description>getting column definitions - Sas did not recognized. I couldn't make it work&lt;BR /&gt;
&lt;BR /&gt;
I'm not a programmer...I'm a mkt consutant and i have a huge amont of data to manipulate.

Message was edited by: elilika</description>
      <pubDate>Tue, 26 May 2009 15:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36355#M9137</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-26T15:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36356#M9138</link>
      <description>If willing to solve the problem (regardless of your focus/perspective), you will need to explain what code you attempted and exactly what error occurred or further explain "getting column definitions - Sas did not recognized. I couldn't make it work".&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 26 May 2009 17:12:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36356#M9138</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-26T17:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36357#M9139</link>
      <description>Try the following Code. Hope this will help.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
   input client sku volume ;&lt;BR /&gt;
   cards;&lt;BR /&gt;
   3020 1000 10&lt;BR /&gt;
   .       1001 3&lt;BR /&gt;
   .       1002 7&lt;BR /&gt;
   5505 2001 15&lt;BR /&gt;
   .       1005 6&lt;BR /&gt;
   .       1004 30&lt;BR /&gt;
   ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data test1(drop=client rename=(temp=client));&lt;BR /&gt;
   set test;&lt;BR /&gt;
   by client notsorted;&lt;BR /&gt;
   retain temp;&lt;BR /&gt;
   if first.client and client ne . then temp=client;&lt;BR /&gt;
   client=temp;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
~Sukanya E</description>
      <pubDate>Tue, 26 May 2009 19:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36357#M9139</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-26T19:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36358#M9140</link>
      <description>sorry my proposal had a mistake.&lt;BR /&gt;
As a comment, the text "getting column definitions" should have been prefixed with an asterisk.&lt;BR /&gt;
 I have updated the code in the earlier message&lt;BR /&gt;
 &lt;BR /&gt;
hope it works for you now.&lt;BR /&gt;
good luck&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 26 May 2009 19:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36358#M9140</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-05-26T19:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36359#M9141</link>
      <description>Thanks Sukanya, it worked!&lt;BR /&gt;
:-)

Message was edited by: elilika</description>
      <pubDate>Wed, 27 May 2009 14:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement/m-p/36359#M9141</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-27T14:31:45Z</dc:date>
    </item>
  </channel>
</rss>

