<?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 pseudo codes execution: if VAR(t+1)&amp;gt;VAR(t) then output VAR(t) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/pseudo-codes-execution-if-VAR-t-1-gt-VAR-t-then-output-VAR-t/m-p/236115#M43235</link>
    <description>&lt;DIV class="post-text"&gt;
&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;I'm just starting to learn SAS, I have a seemingly straightforward logic that I don't know how to execute. If possible, would you please provide me an Example coding?&lt;/P&gt;
&lt;P&gt;What I need to do is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If within the same code, Interest(t+1)is less than Interest(t), then output coupon=interest(t), keep date, code. In the example below, it is observation 6.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;obs.    date    code    interest
1   1/1/2015    1   0.2
2   1/2/2015    1   0.5
3   1/3/2015    1   1.9
4   1/4/2015    1   2.5
5   1/5/2015    1   3.8
6   1/1/2015    2   2.1
7   1/2/2015    2   0
8   1/3/2015    2   0.1
9   1/4/2015    2   0.2
10  1/5/2015    2   0.3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output sample should look like either:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;obs.    date    code    interest  coupon
1       1/1/2015     2    2.1      2.1
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;obs.    date    code    interest  coupon
1   1/1/2015    1        0.2
2   1/2/2015    1        0.5
3   1/3/2015    1        1.9
4   1/4/2015    1        2.5
5   1/5/2015    1        3.8
6   1/1/2015    2        2.1       2.1
7   1/2/2015    2        0
8   1/3/2015    2        0.1
9   1/4/2015    2        0.2
10  1/5/2015    2        0.3
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
    <pubDate>Tue, 24 Nov 2015 00:28:27 GMT</pubDate>
    <dc:creator>BellaLuna</dc:creator>
    <dc:date>2015-11-24T00:28:27Z</dc:date>
    <item>
      <title>pseudo codes execution: if VAR(t+1)&gt;VAR(t) then output VAR(t)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pseudo-codes-execution-if-VAR-t-1-gt-VAR-t-then-output-VAR-t/m-p/236115#M43235</link>
      <description>&lt;DIV class="post-text"&gt;
&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;I'm just starting to learn SAS, I have a seemingly straightforward logic that I don't know how to execute. If possible, would you please provide me an Example coding?&lt;/P&gt;
&lt;P&gt;What I need to do is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If within the same code, Interest(t+1)is less than Interest(t), then output coupon=interest(t), keep date, code. In the example below, it is observation 6.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;obs.    date    code    interest
1   1/1/2015    1   0.2
2   1/2/2015    1   0.5
3   1/3/2015    1   1.9
4   1/4/2015    1   2.5
5   1/5/2015    1   3.8
6   1/1/2015    2   2.1
7   1/2/2015    2   0
8   1/3/2015    2   0.1
9   1/4/2015    2   0.2
10  1/5/2015    2   0.3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output sample should look like either:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;obs.    date    code    interest  coupon
1       1/1/2015     2    2.1      2.1
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;obs.    date    code    interest  coupon
1   1/1/2015    1        0.2
2   1/2/2015    1        0.5
3   1/3/2015    1        1.9
4   1/4/2015    1        2.5
5   1/5/2015    1        3.8
6   1/1/2015    2        2.1       2.1
7   1/2/2015    2        0
8   1/3/2015    2        0.1
9   1/4/2015    2        0.2
10  1/5/2015    2        0.3
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 24 Nov 2015 00:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pseudo-codes-execution-if-VAR-t-1-gt-VAR-t-then-output-VAR-t/m-p/236115#M43235</guid>
      <dc:creator>BellaLuna</dc:creator>
      <dc:date>2015-11-24T00:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: pseudo codes execution: if VAR(t+1)&gt;VAR(t) then output VAR(t)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pseudo-codes-execution-if-VAR-t-1-gt-VAR-t-then-output-VAR-t/m-p/236120#M43236</link>
      <description>&lt;P&gt;You may be able to accomplish this result using multiple ways such as SQL joins, Data steps,etc. But here is one way using "DATA STEP"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
INPUT OBS:3. DATEIN:$9. CODE:$1. INTEREST:3.1;
DATALINES;
1   1/1/2015    1   0.2
2   1/2/2015    1   0.5
3   1/3/2015    1   1.9
4   1/4/2015    1   2.5
5   1/5/2015    1   3.8
6   1/1/2015    2   2.1
7   1/2/2015    2   0
8   1/3/2015    2   0.1
9   1/4/2015    2   0.2
10  1/5/2015    2   0.3
;
RUN;
DATA WANT(KEEP=OBS DATEF CODE PREV_INTEREST COUPON); 
	SET HAVE; 
	DATEF=INPUT(DATEIN,ANYDTDTE.);
	RETAIN PREV_OBS PREV_DATEF PREV_CODE PREV_INTEREST;		
	IF (INTEREST LT PREV_INTEREST) AND (CODE = PREV_CODE)
	THEN 
		DO;
			COUPON=PREV_INTEREST;
			OUTPUT ;
		END;
	PREV_OBS=OBS;
	PREV_DATEF=DATEF;
	PREV_CODE=CODE;
	PREV_INTEREST=INTEREST;
RUN;
PROC PRINT;
	FORMAT DATEF MMDDYY10.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Yields this output....&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs	OBS	CODE	DATEF	PREV_INTEREST	COUPON
1	7	2	01/02/2015	2.1	2.1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hope this helps. Good Luck...!!!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2015 02:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pseudo-codes-execution-if-VAR-t-1-gt-VAR-t-then-output-VAR-t/m-p/236120#M43236</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-11-24T02:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: pseudo codes execution: if VAR(t+1)&gt;VAR(t) then output VAR(t)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pseudo-codes-execution-if-VAR-t-1-gt-VAR-t-then-output-VAR-t/m-p/236121#M43237</link>
      <description>Thank you so much! This helps a lot!</description>
      <pubDate>Tue, 24 Nov 2015 02:56:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pseudo-codes-execution-if-VAR-t-1-gt-VAR-t-then-output-VAR-t/m-p/236121#M43237</guid>
      <dc:creator>BellaLuna</dc:creator>
      <dc:date>2015-11-24T02:56:42Z</dc:date>
    </item>
  </channel>
</rss>

