<?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: data processing in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75070#M21768</link>
    <description>[pre]data input;&lt;BR /&gt;
  input year bank_ID cash_balance;&lt;BR /&gt;
  datalines;&lt;BR /&gt;
2000 1 0&lt;BR /&gt;
2000 2 0&lt;BR /&gt;
2000 3 0&lt;BR /&gt;
2000 4 0&lt;BR /&gt;
2001 1 10&lt;BR /&gt;
2001 2 20&lt;BR /&gt;
2001 3 0&lt;BR /&gt;
2001 4 5&lt;BR /&gt;
2002 1 15&lt;BR /&gt;
2002 2 22&lt;BR /&gt;
2002 3 5&lt;BR /&gt;
2002 4 7&lt;BR /&gt;
2003 1 0&lt;BR /&gt;
2003 2 0&lt;BR /&gt;
2003 3 0&lt;BR /&gt;
2003 4 0&lt;BR /&gt;
2004 1 10&lt;BR /&gt;
2004 2 20&lt;BR /&gt;
2004 3 0&lt;BR /&gt;
2004 4 5&lt;BR /&gt;
2005 1 15&lt;BR /&gt;
2005 2 22&lt;BR /&gt;
2005 3 5&lt;BR /&gt;
2005 4 7&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
proc sort data=input;&lt;BR /&gt;
  by bank_id year;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
data lag;&lt;BR /&gt;
  set input;&lt;BR /&gt;
  time_1 = max(lag1(cash_balance),0);&lt;BR /&gt;
  time_2 = max(lag2(cash_balance),0);&lt;BR /&gt;
  time_3 = max(lag3(cash_balance),0);&lt;BR /&gt;
run;[/pre]</description>
    <pubDate>Sat, 21 Feb 2009 19:55:41 GMT</pubDate>
    <dc:creator>GertNissen</dc:creator>
    <dc:date>2009-02-21T19:55:41Z</dc:date>
    <item>
      <title>data processing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75069#M21767</link>
      <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I have a dataset in the following format:&lt;BR /&gt;
year bank_ID cash_balance&lt;BR /&gt;
&lt;BR /&gt;
2000 1 0&lt;BR /&gt;
2000 2 0&lt;BR /&gt;
2000 3 0&lt;BR /&gt;
2000 4 0&lt;BR /&gt;
2001 1 10&lt;BR /&gt;
2001 2 20&lt;BR /&gt;
2001 3 0&lt;BR /&gt;
2001 4 5&lt;BR /&gt;
2002 1 15&lt;BR /&gt;
2002 2 22&lt;BR /&gt;
2002 3 5&lt;BR /&gt;
2002 4 7&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
2009.......&lt;BR /&gt;
&lt;BR /&gt;
Now, I would like to create three variables, time_1, time_2, time_3.  These three time variables represent &lt;B&gt;presence or absense (0/1) of a bank balance of &amp;gt;$0 for a particular bankID in the previous year, in two years previous, and three year previous.&lt;/B&gt; &lt;BR /&gt;
&lt;BR /&gt;
Example 1.  When SAS is evaluating year 2000, then it should create variables temp_1, temp_2, and temp_3 based on bank balances for the unique bankIDs during years 1999, 1998, and 1997.  Since data for years 1997-1999 are missing, temp_1, temp_2, and temp_3 values for year 2000 should have missing values.  In case of year 2001, data for years 1998 and 1999 are missing, so temp_2 and temp_3 values for year 2001 should be set to missing.&lt;BR /&gt;
&lt;BR /&gt;
Example 2. For year 2003 and bankID 1, bank balance for year 2002 (temp_1) is 15, so temp_1 would be 1, however for 2000 (temp_3) the bank_balance is 0, so value of temp_3 would be 0.  &lt;BR /&gt;
&lt;BR /&gt;
Any suggestions regarding an appropriate SAS program to process this data will be highly appreciated.  Thank you.</description>
      <pubDate>Sat, 21 Feb 2009 16:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75069#M21767</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-21T16:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: data processing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75070#M21768</link>
      <description>[pre]data input;&lt;BR /&gt;
  input year bank_ID cash_balance;&lt;BR /&gt;
  datalines;&lt;BR /&gt;
2000 1 0&lt;BR /&gt;
2000 2 0&lt;BR /&gt;
2000 3 0&lt;BR /&gt;
2000 4 0&lt;BR /&gt;
2001 1 10&lt;BR /&gt;
2001 2 20&lt;BR /&gt;
2001 3 0&lt;BR /&gt;
2001 4 5&lt;BR /&gt;
2002 1 15&lt;BR /&gt;
2002 2 22&lt;BR /&gt;
2002 3 5&lt;BR /&gt;
2002 4 7&lt;BR /&gt;
2003 1 0&lt;BR /&gt;
2003 2 0&lt;BR /&gt;
2003 3 0&lt;BR /&gt;
2003 4 0&lt;BR /&gt;
2004 1 10&lt;BR /&gt;
2004 2 20&lt;BR /&gt;
2004 3 0&lt;BR /&gt;
2004 4 5&lt;BR /&gt;
2005 1 15&lt;BR /&gt;
2005 2 22&lt;BR /&gt;
2005 3 5&lt;BR /&gt;
2005 4 7&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
proc sort data=input;&lt;BR /&gt;
  by bank_id year;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
data lag;&lt;BR /&gt;
  set input;&lt;BR /&gt;
  time_1 = max(lag1(cash_balance),0);&lt;BR /&gt;
  time_2 = max(lag2(cash_balance),0);&lt;BR /&gt;
  time_3 = max(lag3(cash_balance),0);&lt;BR /&gt;
run;[/pre]</description>
      <pubDate>Sat, 21 Feb 2009 19:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75070#M21768</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-02-21T19:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: data processing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75071#M21769</link>
      <description>Looking at your data I think Geniz solution comes only close to what you asked for.&lt;BR /&gt;
&lt;BR /&gt;
May be this might help (not tested):&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
value bool&lt;BR /&gt;
&amp;gt;0 =1&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data lag;&lt;BR /&gt;
set input;&lt;BR /&gt;
time_1 = input(put(lag1(cash_balance),bool.),8.);&lt;BR /&gt;
time_1 = input(put(lag2(cash_balance),bool.),8.);&lt;BR /&gt;
time_1 = input(put(lag3(cash_balance),bool.),8.);&lt;BR /&gt;
run;</description>
      <pubDate>Sun, 22 Feb 2009 01:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75071#M21769</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-02-22T01:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: data processing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75072#M21770</link>
      <description>Thanks Geniz and Patrick.  I will work on your suggestions and get back to the forum very soon.  Any alternate suggestions from other forum members are most welcome.</description>
      <pubDate>Sun, 22 Feb 2009 01:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75072#M21770</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-22T01:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: data processing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75073#M21771</link>
      <description>Tss, tss... and what both solutions where missing so far is what I included now in the end of the code.&lt;BR /&gt;
Not very elegant - but it should work.&lt;BR /&gt;
&lt;BR /&gt;
data input;&lt;BR /&gt;
  input year bank_ID cash_balance;&lt;BR /&gt;
  datalines;&lt;BR /&gt;
2000 1 0&lt;BR /&gt;
2000 2 0&lt;BR /&gt;
2000 3 0&lt;BR /&gt;
2000 4 0&lt;BR /&gt;
2001 1 10&lt;BR /&gt;
2001 2 20&lt;BR /&gt;
2001 3 0&lt;BR /&gt;
2001 4 5&lt;BR /&gt;
2002 1 15&lt;BR /&gt;
2002 2 22&lt;BR /&gt;
2002 3 5&lt;BR /&gt;
2002 4 7&lt;BR /&gt;
2003 1 0&lt;BR /&gt;
2003 2 0&lt;BR /&gt;
2003 3 0&lt;BR /&gt;
2003 4 0&lt;BR /&gt;
2004 1 10&lt;BR /&gt;
2004 2 20&lt;BR /&gt;
2004 3 0&lt;BR /&gt;
2004 4 5&lt;BR /&gt;
2005 1 15&lt;BR /&gt;
2005 2 22&lt;BR /&gt;
2005 3 5&lt;BR /&gt;
2005 4 7&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
proc sort data=input;&lt;BR /&gt;
  by bank_id year;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
proc format;&lt;BR /&gt;
value bool&lt;BR /&gt;
&amp;gt;0 =1&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data lag;&lt;BR /&gt;
set input;&lt;BR /&gt;
by bank_id year;&lt;BR /&gt;
time_1 = input(put(lag1(cash_balance),bool.),8.);&lt;BR /&gt;
time_2 = input(put(lag2(cash_balance),bool.),8.);&lt;BR /&gt;
time_3 = input(put(lag3(cash_balance),bool.),8.);&lt;BR /&gt;
&lt;BR /&gt;
if bank_id ne lag1(bank_id) then time_1=.;&lt;BR /&gt;
if bank_id ne lag2(bank_id) then time_2=.;&lt;BR /&gt;
if bank_id ne lag3(bank_id) then time_3=.;&lt;BR /&gt;
run;

Message was edited by: Patrick</description>
      <pubDate>Sun, 22 Feb 2009 11:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75073#M21771</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-02-22T11:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: data processing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75074#M21772</link>
      <description>Normalizing Boolean and initializing LAGS at BY group breaks.&lt;BR /&gt;
&lt;BR /&gt;
Using the technique of this sample program &lt;A href="http://support.sas.com/kb/24/694.html" target="_blank"&gt;http://support.sas.com/kb/24/694.html&lt;/A&gt; and using a double negative to normalize the flags I suggest this small modification to your program.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data lag;&lt;BR /&gt;
   set input;&lt;BR /&gt;
   by bank_id year;&lt;BR /&gt;
   array time_[3];&lt;BR /&gt;
   time_1 = not not lag1(cash_balance);&lt;BR /&gt;
   time_2 = not not lag2(cash_balance);&lt;BR /&gt;
   time_3 = not not lag3(cash_balance);&lt;BR /&gt;
   if first.bank_id then count = 0;&lt;BR /&gt;
   count + 1;&lt;BR /&gt;
   do _n_ = count to dim(time_);&lt;BR /&gt;
      time_[_n_] = .;&lt;BR /&gt;
      end;&lt;BR /&gt;
   drop count;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   by bank_id;&lt;BR /&gt;
   id bank_id;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
                        cash_&lt;BR /&gt;
    bank_ID    year    balance    time_1    time_2    time_3&lt;BR /&gt;
&lt;BR /&gt;
       1       2000        0         .         .         .&lt;BR /&gt;
               2001       10         0         .         .&lt;BR /&gt;
               2002       15         1         0         .&lt;BR /&gt;
               2003        0         1         1         0&lt;BR /&gt;
               2004       10         0         1         1&lt;BR /&gt;
               2005       15         1         0         1&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
       2       2000        0         .         .         .&lt;BR /&gt;
               2001       20         0         .         .&lt;BR /&gt;
               2002       22         1         0         .&lt;BR /&gt;
               2003        0         1         1         0&lt;BR /&gt;
               2004       20         0         1         1&lt;BR /&gt;
               2005       22         1         0         1&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
       3       2000        0         .         .         .&lt;BR /&gt;
               2001        0         0         .         .&lt;BR /&gt;
               2002        5         0         0         .&lt;BR /&gt;
               2003        0         1         0         0&lt;BR /&gt;
               2004        0         0         1         0&lt;BR /&gt;
               2005        5         0         0         1&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
       4       2000        0         .         .         .&lt;BR /&gt;
               2001        5         0         .         .&lt;BR /&gt;
               2002        7         1         0         .&lt;BR /&gt;
               2003        0         1         1         0&lt;BR /&gt;
               2004        5         0         1         1&lt;BR /&gt;
               2005        7         1         0         1&lt;BR /&gt;
[/pre]</description>
      <pubDate>Sun, 22 Feb 2009 13:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/data-processing/m-p/75074#M21772</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-02-22T13:37:39Z</dc:date>
    </item>
  </channel>
</rss>

