<?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 do I write a macro with array variables to run thru a proc ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257690#M49499</link>
    <description>&lt;P&gt;Correct, I&lt;EM&gt; do&lt;/EM&gt; need the trimmed data&amp;nbsp;per BY group in a data set with the outliers either deleted or set to missing.&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;Within the output for proc univariate or proc mean can you specify an output argument similar to the below that would work? Where I want the descriptive statistics for all the variables within my array (x_1,&amp;nbsp;x_2, x_3....&amp;nbsp;x_56)&amp;nbsp;but I want a seperate table for each variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc mean data= ;&lt;/P&gt;&lt;P&gt;by age;&lt;/P&gt;&lt;P&gt;var x_1 x_2 x_3... x_56;&lt;/P&gt;&lt;P&gt;output&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF var = x_1 THEN output=X_1 mean=average n=n &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;lclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; =lower &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;uclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=upper ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; IF var = x_2 THEN output=X_2 mean=average n=n &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;lclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; =lower &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;uclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=upper ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;IF var = x_3 THEN output=X_3 mean=average n=n &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;lclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; =lower &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;uclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=upper ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;....&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;IF var = x_56 THEN output=X_56 mean=average n=n &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;lclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; =lower &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;uclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=upper ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Mar 2016 19:57:42 GMT</pubDate>
    <dc:creator>eabbo</dc:creator>
    <dc:date>2016-03-18T19:57:42Z</dc:date>
    <item>
      <title>How do I write a macro with array variables to run thru a proc ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257439#M49428</link>
      <description>&lt;P&gt;I have a data set that has&amp;nbsp;50 array&amp;nbsp;variables (x_1, x_2, x_3...) and each variable has around 7000 observations and I need to push&amp;nbsp;each variable thru&amp;nbsp;a macro that will take them&amp;nbsp;thru proc univariate to create a trimmed means for each variable by a group variable (shown as AGE below)&amp;nbsp;and then produce one table that has all of the amended variables in it.&amp;nbsp; Any help with how this macro would be set up would be&amp;nbsp;greatly appreciated.&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;proc univariate data=DATASET &amp;nbsp;trimmed=1 .1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by AGE&lt;BR /&gt;&amp;nbsp;&amp;nbsp; var X_1 X_2 ...&amp;nbsp; ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 20:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257439#M49428</guid>
      <dc:creator>eabbo</dc:creator>
      <dc:date>2016-03-17T20:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a macro with array variables to run thru a proc ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257444#M49431</link>
      <description>&lt;P&gt;If your variables are truly named X_1 X_2 and such then you don't need any macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc univariate data=dataset trimmed=1.1;
   by age;
   var x_1 x_2 x_3 ;
output out=means mean=x_1 x_2 x_3 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just put your list of variables on the Var line and then after the mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 20:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257444#M49431</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-17T20:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a macro with array variables to run thru a proc ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257467#M49437</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77972"&gt;@eabbo﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;that you most likely won't need a macro. However, I'm not quite sure what you mean by "amended variables."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given the large number of variables (times the number of BY groups), you will probably want to create a dataset containing the trimmed means.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Please note that with your specification &lt;FONT face="courier new,courier"&gt;trimmed=1 .1&lt;/FONT&gt; you request two different types of k-times trimmed means: k=1 and k=ceil(n_i&amp;nbsp;&lt;FONT face="symbol"&gt;*&amp;nbsp;&lt;/FONT&gt;0.1) where n_i is the size of the i-th BY group.&amp;nbsp;I think you need to use ODS OUTPUT to get these into a dataset. The MEAN= option of the OUTPUT statement requests the ordinary (untrimmed) means, regardless of the TRIMMED= option in the PROC UNIVARIATE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data */

data have;
array x_[50];
do i=1 to 7000;
  age=51+int(i/2500);
  do j=1 to dim(x_);
    x_[j]=100+10*rannor(2718);
  end;
  output;
end;
drop i j;
run;

/* Write two types of trimmed means to dataset TMEANS */

ods listing close;
ods output TrimmedMeans=tmeans;
proc univariate data=have trimmed=1 .1;
by age;
var x:;
run;
ods listing;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you need the trimmed &lt;EM&gt;data&lt;/EM&gt;, i.e., a dataset where the smallest and largest k values per BY group are deleted or set to missing?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 22:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257467#M49437</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-17T22:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a macro with array variables to run thru a proc ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257690#M49499</link>
      <description>&lt;P&gt;Correct, I&lt;EM&gt; do&lt;/EM&gt; need the trimmed data&amp;nbsp;per BY group in a data set with the outliers either deleted or set to missing.&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;Within the output for proc univariate or proc mean can you specify an output argument similar to the below that would work? Where I want the descriptive statistics for all the variables within my array (x_1,&amp;nbsp;x_2, x_3....&amp;nbsp;x_56)&amp;nbsp;but I want a seperate table for each variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc mean data= ;&lt;/P&gt;&lt;P&gt;by age;&lt;/P&gt;&lt;P&gt;var x_1 x_2 x_3... x_56;&lt;/P&gt;&lt;P&gt;output&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF var = x_1 THEN output=X_1 mean=average n=n &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;lclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; =lower &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;uclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=upper ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; IF var = x_2 THEN output=X_2 mean=average n=n &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;lclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; =lower &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;uclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=upper ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;IF var = x_3 THEN output=X_3 mean=average n=n &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;lclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; =lower &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;uclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=upper ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;....&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;IF var = x_56 THEN output=X_56 mean=average n=n &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;lclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; =lower &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;uclm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=upper ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 19:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257690#M49499</guid>
      <dc:creator>eabbo</dc:creator>
      <dc:date>2016-03-18T19:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a macro with array variables to run thru a proc ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257702#M49503</link>
      <description>&lt;P&gt;Unfortunately, as far as I know, PROC UNIVARIATE does not provide an option to write trimmed (or Winsorized) data to a dataset, and PROC MEANS (and PROC SUMMARY) do not even compute trimmed means.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you'll have to trim your data "manually," e.g., in a data step or with SAS/IML (if available). Earlier this month, there was a &lt;A href="https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-winsorize-variables/m-p/254655" target="_blank"&gt;similar discussion about Winsorizing variables&lt;/A&gt;&amp;nbsp;with valuable contributions by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS﻿&lt;/a&gt;&amp;nbsp;and others. I think it should be possible to adapt code for Winsorizing data in such a way that the outliers are removed or set to missing rather than replaced by less extreme values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a first guess, I could imagine that it'll be helpful to transpose your data (at least temporarily) so that the 56 variables are turned into BY groups of a single variable. 56&lt;FONT face="symbol"&gt;*&lt;/FONT&gt;7000=392000 observations are still easy to handle with SAS. Then you could trim the values within the "combined" BY groups (i.e. the new ones due to transposing within the old ones "BY age") and eventually re-transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just give it a try. If you experience any difficulties, please feel free to&amp;nbsp;ask again. Good luck!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 20:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257702#M49503</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-18T20:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a macro with array variables to run thru a proc ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257776#M49539</link>
      <description>&lt;P&gt;Why do you think you need to winsorize each variable? If your answer is "because there might be outliers," I would note that there are statistical techniques that are robust to outliers, such as robust regression.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Mar 2016 19:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-a-macro-with-array-variables-to-run-thru-a-proc/m-p/257776#M49539</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-03-19T19:51:45Z</dc:date>
    </item>
  </channel>
</rss>

