<?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: Base SAS, How to look prior values of newly creating variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-How-to-look-prior-values-of-newly-creating-variable/m-p/267852#M310378</link>
    <description>Based on your logic as example, I tried and applies the below logic, it works fine,&lt;BR /&gt;retain hhcnt llcnt;&lt;BR /&gt;/* Initialize and Simply giving Value for First 1 to 71 Obs */&lt;BR /&gt;if count &amp;gt;= 1 and count &amp;lt;= 71 then do ;&lt;BR /&gt;hhsig = ' ' ;&lt;BR /&gt;hhcnt = 0 ;&lt;BR /&gt;llsig = ' ' ;&lt;BR /&gt;llcnt = 0 ;&lt;BR /&gt;SIG = ' ' ;&lt;BR /&gt;end;&lt;BR /&gt;/* Obs 72 to 121 - Simply Assign */&lt;BR /&gt;else if count &amp;gt;= 72 and count &amp;lt;= 121 then do ;&lt;BR /&gt;hhsig = '0' ;&lt;BR /&gt;hhcnt = 0 ;&lt;BR /&gt;LLSIG = '0' ;&lt;BR /&gt;llcnt = 0 ;&lt;BR /&gt;SIG = '0' ;&lt;BR /&gt;end;&lt;BR /&gt;/* Obs 122 and above - Simply Assign */&lt;BR /&gt;else if count &amp;gt;= 122 then do;&lt;BR /&gt;if ROC &amp;gt; HH then do;&lt;BR /&gt;if (llcnt &amp;gt;= count - 50) then do ;&lt;BR /&gt;SIG = '0' ;&lt;BR /&gt;hhsig = '0' ;&lt;BR /&gt;end;&lt;BR /&gt;else if (llcnt &amp;lt; count - 50) then do ;&lt;BR /&gt;SIG = '+' ;&lt;BR /&gt;hhsig = '+' ;&lt;BR /&gt;hhcnt = count ;&lt;BR /&gt;end;&lt;BR /&gt;end ;&lt;BR /&gt;else if roc &amp;lt; ll then do ;&lt;BR /&gt;if (hhcnt &amp;gt;= count - 50) then do ;&lt;BR /&gt;SIG = '0' ;&lt;BR /&gt;llsig = '0' ;&lt;BR /&gt;end ;&lt;BR /&gt;else if (hhcnt &amp;lt; count - 50) then do ;&lt;BR /&gt;SIG = '-' ;&lt;BR /&gt;llsig = '-' ;&lt;BR /&gt;llcnt = count ;&lt;BR /&gt;end ;&lt;BR /&gt;end ;&lt;BR /&gt;else do ;&lt;BR /&gt;SIG = '0' ;&lt;BR /&gt;end ;&lt;BR /&gt;end ;</description>
    <pubDate>Tue, 03 May 2016 09:29:36 GMT</pubDate>
    <dc:creator>lakshmiG</dc:creator>
    <dc:date>2016-05-03T09:29:36Z</dc:date>
    <item>
      <title>Base SAS, How to look prior values of newly creating variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-How-to-look-prior-values-of-newly-creating-variable/m-p/266892#M310375</link>
      <description>&lt;P&gt;Hi Friends, Good day!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a new variable called Signal and populate either '+' or '-' or '0'. The condition is, if ROC&amp;gt;HH then '+' and no prior '-' signals for past 50 days. Likewise, if ROC&amp;lt;LL then '-' and no prior '+' signal for past 50 days. ROC, HH and LL are separate variables and have numeric values.&lt;/P&gt;&lt;P&gt;My query is, signal is the variable we are populating, how can we check whether there is prior + or - signs. How should I understand this logic and start coding?&lt;/P&gt;&lt;P&gt;Is it ok to populate + and - using the 1st condition, ROC&amp;gt;HH or ROC&amp;lt;LL and then consider the second condition for every observation?&lt;/P&gt;&lt;P&gt;in brief, we have multiple stocks and each stock has historical dates to current date. for every observation, we have ROC from 22nd observation since it is ROC for N=22 periods, HH AND LL populated from 72nd observation as they are N=50 for ROC(22).&lt;/P&gt;&lt;P&gt;kindly guide to populate signals.&lt;/P&gt;&lt;P&gt;I have also attached 1 stock information from our dataset for clear understanding.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 02:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-How-to-look-prior-values-of-newly-creating-variable/m-p/266892#M310375</guid>
      <dc:creator>lakshmiG</dc:creator>
      <dc:date>2016-04-28T02:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS, How to look prior values of newly creating variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-How-to-look-prior-values-of-newly-creating-variable/m-p/266896#M310376</link>
      <description>&lt;P&gt;I tried to translate your requirement into a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
retain lastH lastL;
set HL; by symbol;
if first.symbol then do;
    lastH = '01JAN1900'd;
    lastL = '01JAN1900'd;
    end;
if missing(ROC) then signal = " ";
else if ROC &amp;gt; HH and intck("DAY", lastL, date) &amp;gt; 50 then do;
    signal = "+";
    lastH = date;
    end;
else if ROC &amp;lt; LL and intck("DAY", lastH, date) &amp;gt; 50 then do;
    signal = "-";
    lastL = date;
    end;
else signal = "0";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Apr 2016 03:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-How-to-look-prior-values-of-newly-creating-variable/m-p/266896#M310376</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-04-28T03:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS, How to look prior values of newly creating variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-How-to-look-prior-values-of-newly-creating-variable/m-p/266898#M310377</link>
      <description>Hi PG Stats, I will look into this logic and apply in my program and let you know if its working. Thanks much for your timely help!!!</description>
      <pubDate>Thu, 28 Apr 2016 04:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-How-to-look-prior-values-of-newly-creating-variable/m-p/266898#M310377</guid>
      <dc:creator>lakshmiG</dc:creator>
      <dc:date>2016-04-28T04:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS, How to look prior values of newly creating variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-How-to-look-prior-values-of-newly-creating-variable/m-p/267852#M310378</link>
      <description>Based on your logic as example, I tried and applies the below logic, it works fine,&lt;BR /&gt;retain hhcnt llcnt;&lt;BR /&gt;/* Initialize and Simply giving Value for First 1 to 71 Obs */&lt;BR /&gt;if count &amp;gt;= 1 and count &amp;lt;= 71 then do ;&lt;BR /&gt;hhsig = ' ' ;&lt;BR /&gt;hhcnt = 0 ;&lt;BR /&gt;llsig = ' ' ;&lt;BR /&gt;llcnt = 0 ;&lt;BR /&gt;SIG = ' ' ;&lt;BR /&gt;end;&lt;BR /&gt;/* Obs 72 to 121 - Simply Assign */&lt;BR /&gt;else if count &amp;gt;= 72 and count &amp;lt;= 121 then do ;&lt;BR /&gt;hhsig = '0' ;&lt;BR /&gt;hhcnt = 0 ;&lt;BR /&gt;LLSIG = '0' ;&lt;BR /&gt;llcnt = 0 ;&lt;BR /&gt;SIG = '0' ;&lt;BR /&gt;end;&lt;BR /&gt;/* Obs 122 and above - Simply Assign */&lt;BR /&gt;else if count &amp;gt;= 122 then do;&lt;BR /&gt;if ROC &amp;gt; HH then do;&lt;BR /&gt;if (llcnt &amp;gt;= count - 50) then do ;&lt;BR /&gt;SIG = '0' ;&lt;BR /&gt;hhsig = '0' ;&lt;BR /&gt;end;&lt;BR /&gt;else if (llcnt &amp;lt; count - 50) then do ;&lt;BR /&gt;SIG = '+' ;&lt;BR /&gt;hhsig = '+' ;&lt;BR /&gt;hhcnt = count ;&lt;BR /&gt;end;&lt;BR /&gt;end ;&lt;BR /&gt;else if roc &amp;lt; ll then do ;&lt;BR /&gt;if (hhcnt &amp;gt;= count - 50) then do ;&lt;BR /&gt;SIG = '0' ;&lt;BR /&gt;llsig = '0' ;&lt;BR /&gt;end ;&lt;BR /&gt;else if (hhcnt &amp;lt; count - 50) then do ;&lt;BR /&gt;SIG = '-' ;&lt;BR /&gt;llsig = '-' ;&lt;BR /&gt;llcnt = count ;&lt;BR /&gt;end ;&lt;BR /&gt;end ;&lt;BR /&gt;else do ;&lt;BR /&gt;SIG = '0' ;&lt;BR /&gt;end ;&lt;BR /&gt;end ;</description>
      <pubDate>Tue, 03 May 2016 09:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-How-to-look-prior-values-of-newly-creating-variable/m-p/267852#M310378</guid>
      <dc:creator>lakshmiG</dc:creator>
      <dc:date>2016-05-03T09:29:36Z</dc:date>
    </item>
  </channel>
</rss>

