<?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: Loop in Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-in-Macro/m-p/194047#M36484</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If we are using univariate we could calculate the statistics of only one variable at a time. So the method you are following is correct. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Apr 2015 13:58:33 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2015-04-12T13:58:33Z</dc:date>
    <item>
      <title>Loop in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-in-Macro/m-p/194046#M36483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi SAS Experts -&lt;/P&gt;&lt;P&gt;I have a macro that calculates acceptable range of a variable. An acceptable range is defined by :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lower Limit = Q1 - 1.5*(Q3-Q1)&lt;/P&gt;&lt;P&gt;Upper Limit = Q3 + 1.5*(Q3-Q1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's a boxplot method of calculating outliers. The macro is working fine. But it is inefficient in terms of its processing as it calculates outliers for each variable in a loop and then capping values. I want proc univariate to be run for all the variables (not in loop) and save output in a dataset and then capping for variables using IF THEN at one time only.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code : -&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options mprint symbolgen; &lt;/P&gt;&lt;P&gt;%macro outliers(input=, vars=, output= );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data &amp;amp;output;&lt;/P&gt;&lt;P&gt;set &amp;amp;input;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let n=%sysfunc(countw(&amp;amp;vars));&lt;/P&gt;&lt;P&gt;%do i= 1 %to &amp;amp;n;&lt;/P&gt;&lt;P&gt;%let val = %scan(&amp;amp;vars,&amp;amp;i);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Calculate the quartiles and inter-quartile range using proc univariate */&lt;/P&gt;&lt;P&gt;proc univariate data=&amp;amp;output noprint;&lt;/P&gt;&lt;P&gt;var &amp;amp;val;&lt;/P&gt;&lt;P&gt;output out=temp QRANGE= IQR Q1= First_Qtl Q3= Third_Qtl;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Extract the upper and lower limits into macro variables */&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set temp;&lt;/P&gt;&lt;P&gt;call symput('QR', IQR);&lt;/P&gt;&lt;P&gt;call symput('Q1', First_Qtl);&lt;/P&gt;&lt;P&gt;call symput('Q3', Third_Qtl);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let ULimit=%sysevalf(&amp;amp;Q3 + 1.5 * &amp;amp;QR);&lt;/P&gt;&lt;P&gt;%let LLimit=%sysevalf(&amp;amp;Q1 - 1.5 * &amp;amp;QR);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Final dataset excluding outliers*/&lt;/P&gt;&lt;P&gt;data &amp;amp;output;&lt;/P&gt;&lt;P&gt;set &amp;amp;output;&lt;/P&gt;&lt;P&gt;if &amp;amp;val &amp;lt; &amp;amp;Llimit then &amp;amp;val = &amp;amp;Llimit;&lt;/P&gt;&lt;P&gt;if &amp;amp;val &amp;gt; &amp;amp;Ulimit then &amp;amp;val = &amp;amp;Ulimit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%outliers(Input=abcd, Vars = a, output= test);&lt;/P&gt;&lt;P&gt;o &lt;/P&gt;&lt;P&gt;Thanks in anticipation!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Apr 2015 09:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-in-Macro/m-p/194046#M36483</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2015-04-12T09:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: Loop in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-in-Macro/m-p/194047#M36484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If we are using univariate we could calculate the statistics of only one variable at a time. So the method you are following is correct. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Apr 2015 13:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-in-Macro/m-p/194047#M36484</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2015-04-12T13:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Loop in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-in-Macro/m-p/194048#M36485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SAS procs are designed to handle a lot of variables in one run on the data.&lt;/P&gt;&lt;P&gt;Even the outputdataset of Univariate&amp;nbsp; &lt;A href="http://support.sas.com/documentation/cdl/en/procstat/66703/HTML/default/viewer.htm#procstat_univariate_syntax21.htm" title="http://support.sas.com/documentation/cdl/en/procstat/66703/HTML/default/viewer.htm#procstat_univariate_syntax21.htm"&gt;Base SAS(R) 9.4 Procedures Guide: Statistical Procedures, Second Edition&lt;/A&gt;&amp;nbsp; It ends with mentioning two variables being processed each getting different suffixes.&lt;/P&gt;&lt;P&gt;You are starting your question with "you are having a macro" There could be a confusion there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Macro-s in SAS are source text base ones (type 2) and not functional processes (type 3) or recorded keyboard/mouse actions (type 1). If you are trying to use macro-s as you used that with that word in Excel or any other programming language leave that behind you and program your logic understanding SAS from scratch &lt;A href="http://en.wikipedia.org/wiki/Macro_(computer_science"&gt;http://en.wikipedia.org/wiki/Macro_(computer_science&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just another question as you are trying to build boxplots &lt;A href="http://nesug.org/proceedings/nesug08/np/np16.pdf" title="http://nesug.org/proceedings/nesug08/np/np16.pdf"&gt;http://nesug.org/proceedings/nesug08/np/np16.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Did you check whether your question is easily solved by the many procs (modern word would be now packages) that are around .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Apr 2015 15:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-in-Macro/m-p/194048#M36485</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2015-04-12T15:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Loop in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-in-Macro/m-p/194049#M36486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For part 1 switch to proc means.&amp;nbsp; I don't think you need a macro for this at all, but perhaps Jaap's paper has illustrated it better than I can here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's two different ways of generating the stats for all variables at once:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;means&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;data&lt;/SPAN&gt;=sashelp.class stackods &lt;SPAN style="color: #0433ff;"&gt;n&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;p25&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;p75&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;qrange&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;median&lt;/SPAN&gt;;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;var&lt;/SPAN&gt; age &lt;SPAN style="color: #0433ff;"&gt;weight&lt;/SPAN&gt; height;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;ods&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;output&lt;/SPAN&gt; summary=want1;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #0433ff;"&gt;output&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;out&lt;SPAN style="color: #000000;"&gt;=want2 &lt;/SPAN&gt;n&lt;SPAN style="color: #000000;"&gt;= &lt;/SPAN&gt;p25&lt;SPAN style="color: #000000;"&gt;= &lt;/SPAN&gt;p75&lt;SPAN style="color: #000000;"&gt;= &lt;/SPAN&gt;qrange&lt;SPAN style="color: #000000;"&gt;= &lt;/SPAN&gt;median&lt;SPAN style="color: #000000;"&gt;=/&lt;/SPAN&gt;autoname&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Apr 2015 16:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-in-Macro/m-p/194049#M36486</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-04-12T16:29:56Z</dc:date>
    </item>
  </channel>
</rss>

