<?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 loop using PROC EXPAND? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51486#M14124</link>
    <description>Great Patrick, that's exactly what I was looking for. I did play around with some of the commands you use, but didn't know about the need for some others.  Also, the structure of your code is very insightful. Thanks!</description>
    <pubDate>Mon, 19 Jul 2010 03:15:37 GMT</pubDate>
    <dc:creator>Sj03rd</dc:creator>
    <dc:date>2010-07-19T03:15:37Z</dc:date>
    <item>
      <title>How to loop using PROC EXPAND?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51483#M14121</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Using PROC EXPAND, I would like to calculate moving averages for different variables. &lt;BR /&gt;
&lt;BR /&gt;
Specifically, consider some variables (say x, y, and z) for which I would like to calculate some backward moving averages (20 observations) with different names (say mx, my, mz) which require 3 different minimum number of observations (let's say 20, 18 or 16). This COULD be done as follows:&lt;BR /&gt;
&lt;BR /&gt;
proc expand data = indta out=outdta method=none;&lt;BR /&gt;
by ID;&lt;BR /&gt;
convert x = mx20 / transformout=(movave 20 trim 20);&lt;BR /&gt;
convert y = my20 / transformout=(movave 20 trim 20);&lt;BR /&gt;
convert z = mz20 / transformout=(movave 20 trim 20);&lt;BR /&gt;
convert x = mx18 / transformout=(movave 20 trim 18);&lt;BR /&gt;
convert y = my18 / transformout=(movave 20 trim 18);&lt;BR /&gt;
convert z = mz18 / transformout=(movave 20 trim 18);&lt;BR /&gt;
convert x = mx16 / transformout=(movave 20 trim 16);&lt;BR /&gt;
convert y = my16 / transformout=(movave 20 trim 16);&lt;BR /&gt;
convert z = mz16 / transformout=(movave 20 trim 16);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
This doesn't sound as a difficult question, but am struggling to create a more flexible solution. I hope someones knows how to automate this, for instance with the following input arguments:&lt;BR /&gt;
&lt;BR /&gt;
%let indta = indata; &lt;BR /&gt;
%let outdta = outdata; &lt;BR /&gt;
%let estdays = 20; &lt;BR /&gt;
%let mindays = 20 18 16; &lt;BR /&gt;
%let VarIn = x y z; &lt;BR /&gt;
%let VarOut = mx my mz; &lt;BR /&gt;
&lt;BR /&gt;
thanks&lt;BR /&gt;
Sjoerd&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Sj03rd

Message was edited by: Sj03rd</description>
      <pubDate>Fri, 16 Jul 2010 20:26:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51483#M14121</guid>
      <dc:creator>Sj03rd</dc:creator>
      <dc:date>2010-07-16T20:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop using PROC EXPAND?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51484#M14122</link>
      <description>Did you have something like the following in mind?&lt;BR /&gt;
&lt;BR /&gt;
%let indta = indata; &lt;BR /&gt;
%let outdta = outdata; &lt;BR /&gt;
%let estdays = 20; &lt;BR /&gt;
%let mindays = 20 18 16; &lt;BR /&gt;
%let VarIn = x y z; &lt;BR /&gt;
%let VarOut = mx my mz; &lt;BR /&gt;
&lt;BR /&gt;
%macro test;&lt;BR /&gt;
  %let ind_1=1;&lt;BR /&gt;
  %do %while (%scan(&amp;amp;mindays,&amp;amp;ind_1) ne );&lt;BR /&gt;
    %let ind_2=1;&lt;BR /&gt;
    %do %while (%scan(&amp;amp;VarIn,&amp;amp;ind_2) ne );&lt;BR /&gt;
      convert %scan(&amp;amp;VarIn,&amp;amp;ind_2) = %scan(&amp;amp;VarOut,&amp;amp;ind_2)20 / transformout=(movave &amp;amp;estdays trim %scan(&amp;amp;mindays,&amp;amp;ind_1))%str(;)&lt;BR /&gt;
      %let ind_2=%eval(&amp;amp;ind_2 +1);&lt;BR /&gt;
    %end;&lt;BR /&gt;
      %let ind_1=%eval(&amp;amp;ind_1 +1);&lt;BR /&gt;
  %end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
proc expand data = &amp;amp;indta out=&amp;amp;outdta method=none;&lt;BR /&gt;
  by ID;&lt;BR /&gt;
  %test&lt;BR /&gt;
run;</description>
      <pubDate>Sat, 17 Jul 2010 14:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51484#M14122</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-07-17T14:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop using PROC EXPAND?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51485#M14123</link>
      <description>Hi:&lt;BR /&gt;
  It looks like you've started to learn a bit about the SAS Macro Facility. It would, indeed, allow you to make your program more flexible and "reusable"... as Patrick's example shows.&lt;BR /&gt;
 &lt;BR /&gt;
  The best introduction to the SAS Macro Facility is this paper:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi28/056-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/056-28.pdf&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
  And there are many, many other useful postings on the SAS Macro Facility in this forum and in the SAS Macro documentation examples. Searching the foum and the documentation and also searching for user group papers on the topic of SAS Macro processing&lt;BR /&gt;
search string:&lt;BR /&gt;
SAS Macro Tutorial beginner &lt;BR /&gt;
&lt;BR /&gt;
 should help you find even more resources.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Sat, 17 Jul 2010 14:51:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51485#M14123</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-17T14:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop using PROC EXPAND?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51486#M14124</link>
      <description>Great Patrick, that's exactly what I was looking for. I did play around with some of the commands you use, but didn't know about the need for some others.  Also, the structure of your code is very insightful. Thanks!</description>
      <pubDate>Mon, 19 Jul 2010 03:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51486#M14124</guid>
      <dc:creator>Sj03rd</dc:creator>
      <dc:date>2010-07-19T03:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop using PROC EXPAND?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51487#M14125</link>
      <description>Thanks for the article Cynthia, I'll have a look at it.</description>
      <pubDate>Mon, 19 Jul 2010 03:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-using-PROC-EXPAND/m-p/51487#M14125</guid>
      <dc:creator>Sj03rd</dc:creator>
      <dc:date>2010-07-19T03:16:34Z</dc:date>
    </item>
  </channel>
</rss>

