<?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: loops and proc univariate in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66641#M19037</link>
    <description>thanks a lot! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Wed, 18 May 2011 01:24:45 GMT</pubDate>
    <dc:creator>fl</dc:creator>
    <dc:date>2011-05-18T01:24:45Z</dc:date>
    <item>
      <title>loops and proc univariate</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66639#M19035</link>
      <description>i want to run a proc univariate several times for different variables. can i do it inside a loop?&lt;BR /&gt;
&lt;BR /&gt;
intuitively, this is what i would expect to do&lt;BR /&gt;
&lt;BR /&gt;
DO sv = 'sv1','sv2','sv3';&lt;BR /&gt;
&lt;BR /&gt;
proc univariate data=sample0 noprint; &lt;BR /&gt;
&lt;BR /&gt;
where exchcd=1; &lt;BR /&gt;
&lt;BR /&gt;
var sv; &lt;BR /&gt;
&lt;BR /&gt;
by date;&lt;BR /&gt;
&lt;BR /&gt;
output out=concat('nyse_',sv)  pctlpts=30 70 pctlpre=sv; &lt;BR /&gt;
&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
what is wrong here?</description>
      <pubDate>Tue, 17 May 2011 21:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66639#M19035</guid>
      <dc:creator>fl</dc:creator>
      <dc:date>2011-05-17T21:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: loops and proc univariate</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66640#M19036</link>
      <description>Hi:&lt;BR /&gt;
  You are on the right track, but with the wrong type of DO loop. The regular DO statement belongs to a DATA step program. Since you cannot use PROC UNIVARIATE "inside" a DATA step program, you need to look to other techniques.&lt;BR /&gt;
 &lt;BR /&gt;
  The SAS language has a separate syntax to replicate and generate "code blocks" for compilation and execution. That separate syntax belongs to the SAS Macro facility.&lt;BR /&gt;
 &lt;BR /&gt;
  This paper is a good introduction to the SAS Macro Facility. &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;
  Previous forum postings have covered topics such as this. There are several different ways to accomplish what you want to do....from the very simple to the very complex. I'd recommend reading the above paper and a few of these and then see what you can accomplish -- starting with some of the simple techniques.&lt;BR /&gt;
&lt;A href="http://www.ats.ucla.edu/stat/sas/code/macro_repeatedproc.htm" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/code/macro_repeatedproc.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/243-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/243-29.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.nesug.org/proceedings/nesug03/bt/bt009.pdf" target="_blank"&gt;http://www.nesug.org/proceedings/nesug03/bt/bt009.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://scott.sherrillmix.com/blog/programmer/sas-macros-letting-sas-do-the-typing/" target="_blank"&gt;http://scott.sherrillmix.com/blog/programmer/sas-macros-letting-sas-do-the-typing/&lt;/A&gt;&lt;BR /&gt;
         &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 18 May 2011 01:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66640#M19036</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-05-18T01:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: loops and proc univariate</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66641#M19037</link>
      <description>thanks a lot! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 18 May 2011 01:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66641#M19037</guid>
      <dc:creator>fl</dc:creator>
      <dc:date>2011-05-18T01:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: loops and proc univariate</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66642#M19038</link>
      <description>Maybe :&lt;BR /&gt;
[pre]&lt;BR /&gt;
%DO sv = sv1 sv2 sv3 ;&lt;BR /&gt;
&lt;BR /&gt;
proc univariate data=sample0 noprint;&lt;BR /&gt;
&lt;BR /&gt;
where exchcd=1;&lt;BR /&gt;
&lt;BR /&gt;
var &amp;amp;sv;&lt;BR /&gt;
&lt;BR /&gt;
by date;&lt;BR /&gt;
&lt;BR /&gt;
output out=nyse_&amp;amp;sv pctlpts=30 70 pctlpre=sv;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%end;</description>
      <pubDate>Wed, 18 May 2011 02:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66642#M19038</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-18T02:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: loops and proc univariate</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66643#M19039</link>
      <description>Hi:&lt;BR /&gt;
  It's very useful to run code before posting it for usage by folks who are new to a particular concept, like macro processing. For example, your posted code generates an ERROR message:&lt;BR /&gt;
[pre]&lt;BR /&gt;
463  %DO sv = sv1 sv2 sv3 ;&lt;BR /&gt;
ERROR: Expected %TO not found in %DO statement.  A dummy macro will be compiled.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
And, your code snippet implies that %DO can be placed in "open" code, which is not possible. A %DO statement must be used inside a macro program.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 18 May 2011 12:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66643#M19039</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-05-18T12:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: loops and proc univariate</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66644#M19040</link>
      <description>Hello FL,&lt;BR /&gt;
&lt;BR /&gt;
Do you really need a do loop? You could get all necessary information by the following code:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc univariate data=sample0 noprint; &lt;BR /&gt;
   where exchcd=1; &lt;BR /&gt;
   var sv1 sv2 sv3; &lt;BR /&gt;
   by date;&lt;BR /&gt;
   output out=nyse pctlpts=30 70 pctlpre=sv1 sv2 sv3; &lt;BR /&gt;
run; &lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 18 May 2011 13:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66644#M19040</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-18T13:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: loops and proc univariate</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66645#M19041</link>
      <description>Hi.&lt;BR /&gt;
Cynthia. The code i wrote is not tested, just show an example.&lt;BR /&gt;
Yes.You maybe right for new folk it is very helpful to find some information about this&lt;BR /&gt;
by himself before posting .&lt;BR /&gt;
And I also sure macro can do it. &lt;BR /&gt;
Sorry.I think use %scan and %do %while() and %eval() to get that.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Thu, 19 May 2011 00:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loops-and-proc-univariate/m-p/66645#M19041</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-19T00:50:17Z</dc:date>
    </item>
  </channel>
</rss>

