<?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: Prev and Next objects in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9591#M547</link>
    <description>Thanks a lot...Ill give this a try.&lt;BR /&gt;
&lt;BR /&gt;
Cynthia, you are correct, I created days, freq and sas_date.</description>
    <pubDate>Fri, 01 Oct 2010 10:31:02 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-10-01T10:31:02Z</dc:date>
    <item>
      <title>Prev and Next objects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9585#M541</link>
      <description>Question...I have a variable, Frequency, that represents a period of time for a specific record, either monthly (M) or quarterly (Q).  It was created by using actual to/from dates in my data set, which is a list of sales reports by agent by reporting dates (eg. Jan 1, 2009 to Mar 31, 2009).  I have few periods for a few agents that are neither monthly or quarterly (currently represented by X) (for example, account 111 submits sales every quarter, except for one, when she submitted it after 43 days..after this submission, she returned to submitting every quarter..., in other situations, the are for 2 days only as the person left the organization and this is the final submission)&lt;BR /&gt;
&lt;BR /&gt;
I am trying to use prev. and next. steps (I have about a million records) to identify these odd periods...in situations where the odd record is the last one, the fix is simple (using the first. and last. objects) but I am trying to use prev. and next. objects to identify those agents that did not change their reporting period or leave the org...they just had one odd reporting period in their files.&lt;BR /&gt;
&lt;BR /&gt;
data A_prod1;&lt;BR /&gt;
set A_prod1;&lt;BR /&gt;
by frequency;&lt;BR /&gt;
if frequency=X and prev.frequency=next.frequency then frequency=prev.frequency;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
This is telling me that prev. is not an object, but I can see that it is...my issue is syntax I'm sure, but have no idea what to do.&lt;BR /&gt;
&lt;BR /&gt;
Any help would be appreciated.  Thanks</description>
      <pubDate>Thu, 30 Sep 2010 12:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9585#M541</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-30T12:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Prev and Next objects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9586#M542</link>
      <description>Hi:&lt;BR /&gt;
  Can you point to a place in the documentation that discusses the use of PREV. and NEXT.?? I am not familiar with that syntax construction.&lt;BR /&gt;
&lt;BR /&gt;
  You say that you know that PREV.FREQUENCY and NEXT.FREQUENCY are available because you can "see that it is" -- how do you see PREV.FREQUENCY and NEXT.FREQUENCY??&lt;BR /&gt;
&lt;BR /&gt;
  When you use a BY statement, such as BY FREQUENCY, I would expect that the only automatic variables available to you would be FIRST.FREQUENCY and LAST.FREQUENCY. However, I would also expect, given your description of the data, that you would not want to deal with ALL the frequency counts in the data, but would want a further breakdown by AGENT...so I'd expect to see something like:&lt;BR /&gt;
BY AGENT FREQUENCY; &lt;BR /&gt;
instead of just BY FREQUENCY. &lt;BR /&gt;
&lt;BR /&gt;
Where did the data come from??? Was it from a summary procedure like PROC FREQ or PROC MEANS?? &lt;BR /&gt;
&lt;BR /&gt;
Can you show a mini-subset of what your dataset A_prod1 looks like??? Or show how A_prod1 was created??&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 30 Sep 2010 17:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9586#M542</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-09-30T17:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: Prev and Next objects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9587#M543</link>
      <description>Hi there...I assumed prev and next would function the same as first. and last., but I can see through the documentation it likely doesn't.&lt;BR /&gt;
&lt;BR /&gt;
It's a raw data file...if you see in the pattern, the September 20th start period is out of the ordinary...in this situation, I am trying to populate the variable Freq for that period with an M.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Acct         Start                         End                          Amount     Days        Freq          SasDate&lt;BR /&gt;
111	2009-03-22	2009-04-25	41131.54	34	M	17978&lt;BR /&gt;
111	2009-04-26	2009-05-23	33244.07	27	M	18013&lt;BR /&gt;
111	2009-05-24	2009-06-20	35213.05	27	M	18041&lt;BR /&gt;
111	2009-06-21	2009-07-25	44396.78	34	M	18069&lt;BR /&gt;
111	2009-07-26	2009-08-22	34813.28	27	M	18104&lt;BR /&gt;
111	2009-08-23	2009-09-19	34883.25	27	M	18132&lt;BR /&gt;
111	2009-09-20	2009-10-31	50514.43	41	       0	18160&lt;BR /&gt;
111	2009-11-01	2009-11-28	37537.01	27	M	18202&lt;BR /&gt;
111	2009-11-29	2009-12-26	32868.09	27	M	18230&lt;BR /&gt;
111	2009-12-27	2010-01-30	42070.19	34	M	18258&lt;BR /&gt;
111	2010-01-31	2010-02-27	33186.61	27	M	18293&lt;BR /&gt;
111	2010-02-28	2010-03-27	32800.06	27	M	18321&lt;BR /&gt;
111	2010-03-28	2010-05-01	42657.51	34	M	18349&lt;BR /&gt;
111	2010-05-02	2010-05-29	34714.33	27	M	18384&lt;BR /&gt;
111	2010-05-30	2010-06-26	34715.91	27	M	18412</description>
      <pubDate>Thu, 30 Sep 2010 18:13:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9587#M543</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-30T18:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Prev and Next objects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9588#M544</link>
      <description>Hi:&lt;BR /&gt;
  Does this mean that you already have a program that generates FREQUENCY??? Are ALL of these variables in your original RAW data file???&lt;BR /&gt;
Acct Start End Amount Days Freq SasDate&lt;BR /&gt;
 &lt;BR /&gt;
Or, do you calculate DAYS, FREQ and SASDATE??? Or have they already been calculated? It sounds to me like you are calculating FREQ -- is that how some values are already set to 'M' and the value for Sept 20-Oct31 is set to 0??&lt;BR /&gt;
 &lt;BR /&gt;
If you calculate FREQ, can you post the code that you use to calculate FREQ??&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 30 Sep 2010 18:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9588#M544</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-09-30T18:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Prev and Next objects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9589#M545</link>
      <description>To get the previous value, you need to use the lag function.  Getting the next value is a little trickier.  I’ve done that below by using a second set statement.  The check against _n_ is needed to prevent the EOF marker from being prematurely encountered on the 2nd set statement.  Your first post used the condition “if frequency = X.”  I did not know what the variable X was so I changed the condition to “if freq ne ‘M’.”&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
input Acct $ Start :anydtdte10. End :anydtdte10. Amount Days Freq $ SasDate;&lt;BR /&gt;
datalines;&lt;BR /&gt;
111 2009-03-22 2009-04-25 41131.54 34 M 17978&lt;BR /&gt;
111 2009-04-26 2009-05-23 33244.07 27 M 18013&lt;BR /&gt;
111 2009-05-24 2009-06-20 35213.05 27 M 18041&lt;BR /&gt;
111 2009-06-21 2009-07-25 44396.78 34 M 18069&lt;BR /&gt;
111 2009-07-26 2009-08-22 34813.28 27 M 18104&lt;BR /&gt;
111 2009-08-23 2009-09-19 34883.25 27 M 18132&lt;BR /&gt;
111 2009-09-20 2009-10-31 50514.43 41 0 18160&lt;BR /&gt;
111 2009-11-01 2009-11-28 37537.01 27 M 18202&lt;BR /&gt;
111 2009-11-29 2009-12-26 32868.09 27 M 18230&lt;BR /&gt;
111 2009-12-27 2010-01-30 42070.19 34 M 18258&lt;BR /&gt;
111 2010-01-31 2010-02-27 33186.61 27 M 18293&lt;BR /&gt;
111 2010-02-28 2010-03-27 32800.06 27 M 18321&lt;BR /&gt;
111 2010-03-28 2010-05-01 42657.51 34 M 18349&lt;BR /&gt;
111 2010-05-02 2010-05-29 34714.33 27 M 18384&lt;BR /&gt;
111 2010-05-30 2010-06-26 34715.91 27 M 18412 &lt;BR /&gt;
;;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data temp1;&lt;BR /&gt;
	set temp nobs=n;&lt;BR /&gt;
	if _n_ ne (n-1) then set temp(firstobs=2 keep=freq rename=(freq=nextfreq));&lt;BR /&gt;
	lastfreq = lag(freq);&lt;BR /&gt;
	if _n_ = n then nextfreq = '';&lt;BR /&gt;
&lt;BR /&gt;
	if freq ne 'M' and lastfreq = nextfreq then freq = lastfreq;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=temp1;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]

Message was edited by: polingjw</description>
      <pubDate>Thu, 30 Sep 2010 19:01:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9589#M545</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2010-09-30T19:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Prev and Next objects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9590#M546</link>
      <description>Some similar methods for accomplishing the same thing can be found at:&lt;BR /&gt;
&lt;URL&gt;http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back&amp;gt;/url&amp;gt;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art&lt;/URL&gt;</description>
      <pubDate>Thu, 30 Sep 2010 22:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9590#M546</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-09-30T22:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Prev and Next objects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9591#M547</link>
      <description>Thanks a lot...Ill give this a try.&lt;BR /&gt;
&lt;BR /&gt;
Cynthia, you are correct, I created days, freq and sas_date.</description>
      <pubDate>Fri, 01 Oct 2010 10:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prev-and-Next-objects/m-p/9591#M547</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-01T10:31:02Z</dc:date>
    </item>
  </channel>
</rss>

