<?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: Retaining values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108022#M22479</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is not a problem.&lt;/P&gt;&lt;P&gt;Array can hold 22k elements, That is easy .&lt;/P&gt;&lt;P&gt;Only if your data looks exactly like what you posed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data vnt;
input id 2. dt $6. vl 4.;
datalines;
1 1q2007 200
2 1q2007 200
3 1q2007 200
1 2q2007 20
2 2q2007 120
3 2q2007 620
1 3q2007 150
2 3q2007 250
3 3q2007 700
1 4q2007 50
2 4q2007 100
3 4q2007 300
;
run;
proc sql noprint;
select count(distinct id) into : n from vnt;
quit;
%put &amp;amp;n ;
data want;
 set vnt;
 array _a{&amp;amp;n} _temporary_ (&amp;amp;n*0);
 if vl lt 500 then do;sr=vl+_a{id};_a{id}=sr;end;
&amp;nbsp; else do;sr=vl;_a{id}=vl; end;
run;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 May 2012 08:00:34 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2012-05-10T08:00:34Z</dc:date>
    <item>
      <title>Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108013#M22470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data vnt;&lt;/P&gt;&lt;P&gt;input id 2. dt $6. vl 4.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 1q2007 200&lt;/P&gt;&lt;P&gt;2 1q2007 200&lt;/P&gt;&lt;P&gt;3 1q2007 200&lt;/P&gt;&lt;P&gt;1 2q2007 20&lt;/P&gt;&lt;P&gt;2 2q2007 120&lt;/P&gt;&lt;P&gt;3 2q2007 620&lt;/P&gt;&lt;P&gt;1 3q2007 150&lt;/P&gt;&lt;P&gt;2 3q2007 250&lt;/P&gt;&lt;P&gt;3 3q2007 700&lt;/P&gt;&lt;P&gt;1 4q2007 50&lt;/P&gt;&lt;P&gt;2 4q2007 100&lt;/P&gt;&lt;P&gt;3 4q2007 300&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to get this output as i.e&amp;nbsp; when ever my sr val is &amp;lt;500 then i have to add my vl of particular qrt id up to reach &amp;gt;=500&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sr&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="256"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD align="right" height="17" width="64"&gt;1&lt;/TD&gt;&lt;TD width="64"&gt;1q2007&lt;/TD&gt;&lt;TD align="right" width="64"&gt;200&lt;/TD&gt;&lt;TD align="right" width="64"&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;2&lt;/TD&gt;&lt;TD&gt;1q2007&lt;/TD&gt;&lt;TD align="right"&gt;200&lt;/TD&gt;&lt;TD align="right"&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;3&lt;/TD&gt;&lt;TD&gt;1q2007&lt;/TD&gt;&lt;TD align="right"&gt;200&lt;/TD&gt;&lt;TD align="right"&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;1&lt;/TD&gt;&lt;TD&gt;2q2007&lt;/TD&gt;&lt;TD align="right"&gt;20&lt;/TD&gt;&lt;TD align="right"&gt;220&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;2&lt;/TD&gt;&lt;TD&gt;2q2007&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;TD align="right"&gt;320&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;3&lt;/TD&gt;&lt;TD&gt;2q2007&lt;/TD&gt;&lt;TD align="right"&gt;620&lt;/TD&gt;&lt;TD align="right"&gt;620&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;1&lt;/TD&gt;&lt;TD&gt;3q2007&lt;/TD&gt;&lt;TD align="right"&gt;150&lt;/TD&gt;&lt;TD align="right"&gt;370&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;2&lt;/TD&gt;&lt;TD&gt;3q2007&lt;/TD&gt;&lt;TD align="right"&gt;250&lt;/TD&gt;&lt;TD align="right"&gt;570&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;3&lt;/TD&gt;&lt;TD&gt;3q2007&lt;/TD&gt;&lt;TD align="right"&gt;700&lt;/TD&gt;&lt;TD align="right"&gt;700&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;1&lt;/TD&gt;&lt;TD&gt;4q2007&lt;/TD&gt;&lt;TD align="right"&gt;50&lt;/TD&gt;&lt;TD align="right"&gt;420&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;2&lt;/TD&gt;&lt;TD&gt;4q2007&lt;/TD&gt;&lt;TD align="right"&gt;100&lt;/TD&gt;&lt;TD align="right"&gt;670&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;3&lt;/TD&gt;&lt;TD&gt;4q2007&lt;/TD&gt;&lt;TD align="right"&gt;300&lt;/TD&gt;&lt;TD align="right"&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tried with this piece&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data sdf;&lt;/P&gt;&lt;P&gt;set vnt;&lt;/P&gt;&lt;P&gt;sr=0;&lt;/P&gt;&lt;P&gt;a1=dt;&lt;/P&gt;&lt;P&gt;retain vl&lt;/P&gt;&lt;P&gt;if sr&amp;lt;500 then&lt;/P&gt;&lt;P&gt;sr=sr+vl;&lt;/P&gt;&lt;P&gt;by id notsorted;&lt;/P&gt;&lt;P&gt;put _all_;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;please help me&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data sdf;&lt;/P&gt;&lt;P&gt;set vnt;&lt;/P&gt;&lt;P&gt;sr=0;&lt;/P&gt;&lt;P&gt;a1=dt;&lt;/P&gt;&lt;P&gt;if sr&amp;lt;500 then do until (sr&amp;gt;=500);&lt;/P&gt;&lt;P&gt;sr=sr+vl;&lt;/P&gt;&lt;P&gt;put sr;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;by id notsorted;&lt;/P&gt;&lt;P&gt;put _all_;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here problem is when my value vl is &amp;lt; 500 then i have to go back to 1 qtr and add prev qtr vl corresponds to the id&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 17:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108013#M22470</guid>
      <dc:creator>BobyGadu</dc:creator>
      <dc:date>2012-05-08T17:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108014#M22471</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data vnt;&lt;/P&gt;&lt;P&gt;input id 2. dt $6. vl 4.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 1q2007 200&lt;/P&gt;&lt;P&gt;2 1q2007 200&lt;/P&gt;&lt;P&gt;3 1q2007 200&lt;/P&gt;&lt;P&gt;1 2q2007 20&lt;/P&gt;&lt;P&gt;2 2q2007 120&lt;/P&gt;&lt;P&gt;3 2q2007 620&lt;/P&gt;&lt;P&gt;1 3q2007 150&lt;/P&gt;&lt;P&gt;2 3q2007 250&lt;/P&gt;&lt;P&gt;3 3q2007 700&lt;/P&gt;&lt;P&gt;1 4q2007 50&lt;/P&gt;&lt;P&gt;2 4q2007 100&lt;/P&gt;&lt;P&gt;3 4q2007 300&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;proc sort data=vnt;&lt;/P&gt;&lt;P&gt;by id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set vnt;&lt;/P&gt;&lt;P&gt;by id;&lt;/P&gt;&lt;P&gt;retain sr;&lt;/P&gt;&lt;P&gt;if first.id then sr=0;&lt;/P&gt;&lt;P&gt;sr=ifn(vl&amp;lt;=500, sr+vl*(vl&amp;lt;=500), vl);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 18:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108014#M22471</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-05-08T18:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108015#M22472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;what is your desired output?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 19:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108015#M22472</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-05-08T19:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108016#M22473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;for me the data should not be sorted coz its millions of records as history then i will get fresh quarter file and have to append it i need without sorting the data data will be according to quarter&lt;/P&gt;&lt;P&gt;desired output is&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sr&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" height="288" style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff; width: 218px; height: 281px;" width="218"&gt;&lt;TBODY style="font-style: inherit; font-family: inherit;"&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;" width="64"&gt;1&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;" width="64"&gt;1q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;" width="64"&gt;200&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;" width="64"&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;2&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;1q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;200&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;3&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;1q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;200&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;1&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;2q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;20&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;220&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;2&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;2q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;120&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;320&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;3&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;2q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;620&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;620&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;1&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;3q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;150&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;370&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;2&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;3q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;250&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;570&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;3&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;3q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;700&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;700&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;1&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;4q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;50&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;420&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;2&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;4q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;100&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;670&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="font-style: inherit; font-family: inherit;"&gt;&lt;TD align="right" height="17" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;3&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;4q2007&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;300&lt;/TD&gt;&lt;TD align="right" style="padding-right: 4px; padding-left: 4px; font-style: inherit; font-family: inherit; border-color: black; border-style: solid;"&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 02:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108016#M22473</guid>
      <dc:creator>BobyGadu</dc:creator>
      <dc:date>2012-05-09T02:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108017#M22474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Very interesting. It is dynamically changing value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data vnt;
input id 2. dt $6. vl 4.;
datalines;
1 1q2007 200
2 1q2007 200
3 1q2007 200
1 2q2007 20
2 2q2007 120
3 2q2007 620
1 3q2007 150
2 3q2007 250
3 3q2007 700
1 4q2007 50
2 4q2007 100
3 4q2007 300
;
run;
data want;
 set vnt;
 array _a{3} _temporary_ (0 0 0);
 if vl lt 500 then do;sr=vl+_a{id};_a{id}=sr;end;
&amp;nbsp; else do;sr=vl;_a{id}=vl; end;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 08:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108017#M22474</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-05-09T08:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108018#M22475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But there are 22k distinct&amp;nbsp; ids but there are only 20 values for quarters so it array have to be with dt values which are limited&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 13:15:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108018#M22475</guid>
      <dc:creator>BobyGadu</dc:creator>
      <dc:date>2012-05-09T13:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108019#M22476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Under the conditions you have outlined, I doubt you will get a practical solution.&amp;nbsp; I hope somebody proves me wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might be better served keeping each quarter separate instead of creating one huge file.&amp;nbsp; Storing them as SAS data sets, each already sorted by ID, would give you enough flexibility.&amp;nbsp; Each program could choose which quarters to bring in, and could choose the order:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set q1_2007&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; q2_2007&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; q3_2007;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by id dt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set q1_2007&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; q2_2007&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; q3_2007&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by dt id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Neither DATA step would require any sorting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 14:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108019#M22476</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-05-09T14:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108020#M22477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;NO it has to be in one table as reference and every quarter have to be appended &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 14:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108020#M22477</guid>
      <dc:creator>BobyGadu</dc:creator>
      <dc:date>2012-05-09T14:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108021#M22478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Perhaps the hashing experts should take a look??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Without hashing, this could be done if you have a ton of memory (basically enough memory to hold the entire data set in a couple of two-dimensional arrays).&amp;nbsp; But if the data set is so large that sorting isn't practical, then I question whether such large arrays would be possible.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 15:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108021#M22478</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-05-09T15:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108022#M22479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is not a problem.&lt;/P&gt;&lt;P&gt;Array can hold 22k elements, That is easy .&lt;/P&gt;&lt;P&gt;Only if your data looks exactly like what you posed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data vnt;
input id 2. dt $6. vl 4.;
datalines;
1 1q2007 200
2 1q2007 200
3 1q2007 200
1 2q2007 20
2 2q2007 120
3 2q2007 620
1 3q2007 150
2 3q2007 250
3 3q2007 700
1 4q2007 50
2 4q2007 100
3 4q2007 300
;
run;
proc sql noprint;
select count(distinct id) into : n from vnt;
quit;
%put &amp;amp;n ;
data want;
 set vnt;
 array _a{&amp;amp;n} _temporary_ (&amp;amp;n*0);
 if vl lt 500 then do;sr=vl+_a{id};_a{id}=sr;end;
&amp;nbsp; else do;sr=vl;_a{id}=vl; end;
run;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 08:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108022#M22479</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-05-10T08:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108023#M22480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data is not exactly like that but my need is like retain the value by when i get recent qtr file when my vl is &amp;lt;500 i have to go back to previous qtr and add previous qtr id vl and count how many qtrs i went back to get sr&amp;gt;=500 ,if i take the qtrs values in array and then proceed?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 11:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108023#M22480</guid>
      <dc:creator>BobyGadu</dc:creator>
      <dc:date>2012-05-10T11:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108024#M22481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh. Maybe I understood what you mean.&lt;/P&gt;&lt;P&gt;I will give you some code after twelve hours.&lt;/P&gt;&lt;P&gt;Sorry, I have to leave now, It is too late .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 12:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108024#M22481</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-05-10T12:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108025#M22482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you very much for understanding the problem and i tried with the above code but returning the following error&lt;/P&gt;&lt;P&gt;ERROR: Array subscript out of range at line 30 column 24.&lt;/P&gt;&lt;P&gt;when i take off the distinct in sql its running&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 13:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108025#M22482</guid>
      <dc:creator>BobyGadu</dc:creator>
      <dc:date>2012-05-10T13:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108026#M22483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Haha.&lt;/P&gt;&lt;P&gt;OK. I have some free time now. Check out whether it is what you want .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data vnt;
input id 2. dt $6. vl 4.;
datalines;
1 1q2007 200
2 1q2007 200
3 1q2007 200
1 2q2007 20
2 2q2007 120
3 2q2007 620
1 3q2007 150
2 3q2007 250
3 3q2007 700
1 4q2007 50
2 4q2007 100
3 4q2007 300
;
run;
data _vnt(drop=_dt);
 set vnt(rename=(dt=_dt));
&amp;nbsp; dt=input(catx('q',scan(_dt,-1,'q'),scan(_dt,1,'q')),yyq7.);
&amp;nbsp; format dt yyq7.;
run;

data want(drop=_: ) ;
if _n_ eq 1 then do;
 length id&amp;nbsp; dt&amp;nbsp; vl&amp;nbsp; 8; *if 0 then set _vnt;
 declare hash ha(dataset:'_vnt');
&amp;nbsp; ha.definekey('id','dt');
&amp;nbsp; ha.definedata('vl');
&amp;nbsp; ha.definedone();
 end;
 set _vnt;
if vl lt 500 then do;
 _dt=dt;_vl=vl;sr=vl;how_many=0;
 dt=intnx('qtr',dt,-1);
 do while(ha.find() eq 0);
&amp;nbsp;&amp;nbsp; sr+vl;
&amp;nbsp;&amp;nbsp; how_many+1;
&amp;nbsp;&amp;nbsp; dt=intnx('qtr',dt,-1);
&amp;nbsp;&amp;nbsp; if sr ge 500 then leave;
 end;
 dt=_dt;vl=_vl;
end;
else do;sr=vl; how_many=0;end;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 14:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108026#M22483</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-05-10T14:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108027#M22484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you I will keep working on the data &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 17:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values/m-p/108027#M22484</guid>
      <dc:creator>BobyGadu</dc:creator>
      <dc:date>2012-05-10T17:30:28Z</dc:date>
    </item>
  </channel>
</rss>

