<?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: How to go over a table multiple times but changing the set of observations each time? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542751#M7605</link>
    <description>&lt;P&gt;Excellent!&lt;/P&gt;&lt;P&gt;I used this script and it worked seamlessly!&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
    <pubDate>Wed, 13 Mar 2019 12:42:35 GMT</pubDate>
    <dc:creator>eduqlm</dc:creator>
    <dc:date>2019-03-13T12:42:35Z</dc:date>
    <item>
      <title>How to go over a table multiple times but changing the set of observations each time?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542532#M7563</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;I have been searching for a solution to solve something I have to do, but I can't find the exact procedure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Short: I need to calculate standar deviation in a given table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Long: The table has for example 490 observations, something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATE       USD   PREV  LN        Id  STD&lt;BR /&gt;---------- ----- ----- --------- --- ----------
2019-01-04 37,36 37,45 -0,002414 1
2019-01-03 37,45 37,64 -0,004882 2
2019-01-02 37,64 37,67 -0,000805 3
2018-12-28 37,67 38,32 -0,017166 4
2018-12-27 38,32 38,56 -0,006324 5
...
2017-12-26 18,33 18,07 0,014333 250
2017-12-22 18,07 17,94 0,007364 251
2017-12-21 17,94 17,76 0,010315 252
2017-12-20 17,76 17,62 0,007723 253
2017-12-19 17,62 17,57 0,002921 254
...
2017-01-09 15,89 15,81 0,005206 486
2017-01-06 15,81 15,96 -0,009883 487
2017-01-05 15,96 16,08 -0,007364 488
2017-01-04 16,08 15,94 0,008900 489
2017-01-03 15,94 15,94 0,000031 490&lt;/PRE&gt;&lt;P&gt;USD: Dollar Exchange Rate&lt;BR /&gt;PREV: Dollar Exchange Rate from the previous day&lt;BR /&gt;LN: logarithm of (USD / PREV)&lt;BR /&gt;Id: As I'm working with only labour days I created this column to ease the look up for observations&lt;/P&gt;&lt;P&gt;STD: The variable I need to update&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to do this:&lt;BR /&gt;- For DATE 2019-01-04 I need to calculate standard deviation for the observations (Id) 1 to 252 (that would be 2017-12-21) and update the value in "STD" variable (just for the record this number is 0,017168724)&lt;BR /&gt;-For the next DATE (2019-01-03) I need to calculate standard deviation but now for the observations 2 to 253 (that would be 2017-12-20) and update the value in "STD" variable (just for the record this number is 0,017167976)&lt;BR /&gt;And so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I managed to calculate it one by one preselecting the first 252 observations with something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL OUTOBS = 252;
    CREATE TABLE WORK.DATA03 AS
    SELECT *
    FROM WORK.DATA02
    WHERE DATE &amp;lt;= '04JAN2019'D;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
    CREATE TABLE WORK.DATA04 AS
    SELECT MAX (DATE) FORMAT YYMMDD10. AS MaxDate,
    STD (LN) AS STDDEV,
    DATETIME () FORMAT = DATETIME20.2 AS ProcessDate
    FROM WORK.DATA03;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I would like a more elegant solution to go over the table and get it full updated.&lt;BR /&gt;I found some scripts using a loop but I need to loop multiple times, changing the set of observations each time.&lt;/P&gt;&lt;P&gt;I hope I made my self clear.&lt;/P&gt;&lt;P&gt;Thanks in advance!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 18:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542532#M7563</guid>
      <dc:creator>eduqlm</dc:creator>
      <dc:date>2019-03-12T18:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to go over a table multiple times but changing the set of observations each time?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542538#M7565</link>
      <description>&lt;P&gt;PROC EXPAND will do this. If you don't have access to PROC EXPAND (because its not part of your SAS license), there are other ways, but I'm not familiar with them, however a search of this forum ought to find the proper methods.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 18:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542538#M7565</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-03-12T18:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to go over a table multiple times but changing the set of observations each time?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542553#M7571</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;Thanks for the response.&lt;/P&gt;&lt;P&gt;I been reading for it in the documentation, but it's not exactly what I need.&lt;/P&gt;&lt;P&gt;I need to select observations 1 to 252 and update column STD in observation 1.&lt;/P&gt;&lt;P&gt;Then select observations 2 to 253 and update column STD in observation 2.&lt;/P&gt;&lt;P&gt;And so on.&lt;/P&gt;&lt;P&gt;May be I'm missing something in PROC EXPAND?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 19:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542553#M7571</guid>
      <dc:creator>eduqlm</dc:creator>
      <dc:date>2019-03-12T19:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to go over a table multiple times but changing the set of observations each time?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542555#M7572</link>
      <description>&lt;P&gt;EXPAND will compute the moving standard deviations of each group of 252 observations and store them in a new data set. Then you can merge the results in the new data set into the original data set any way you need them.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 19:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542555#M7572</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-03-12T19:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to go over a table multiple times but changing the set of observations each time?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542576#M7577</link>
      <description>&lt;P&gt;An example calculating 12 month forward rolling STD using SASHELP data with proc expand:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.stocks out=stocks; by stock date; run;

proc expand data=stocks out=stocksSTD;
by stock;
id date;
convert Close=Close12Std / transformout=(reverse movstd 12 reverse );
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 21:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542576#M7577</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-12T21:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to go over a table multiple times but changing the set of observations each time?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542749#M7604</link>
      <description>&lt;P&gt;Perfect! It was giving me an error because I writing "STD" instead of "MOVSTD"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Wrong: TRANSFORMOUT = (REVERSE STD 252 REVERSE)

Correct: TRANSFORMOUT = (REVERSE MOVSTD 252 REVERSE)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 12:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542749#M7604</guid>
      <dc:creator>eduqlm</dc:creator>
      <dc:date>2019-03-13T12:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to go over a table multiple times but changing the set of observations each time?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542751#M7605</link>
      <description>&lt;P&gt;Excellent!&lt;/P&gt;&lt;P&gt;I used this script and it worked seamlessly!&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 12:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-go-over-a-table-multiple-times-but-changing-the-set-of/m-p/542751#M7605</guid>
      <dc:creator>eduqlm</dc:creator>
      <dc:date>2019-03-13T12:42:35Z</dc:date>
    </item>
  </channel>
</rss>

