<?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: PROC UNIVARIATE PERCENTILES BY VARIABLE IN OUTPUT DATASET in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-UNIVARIATE-PERCENTILES-BY-VARIABLE-IN-OUTPUT-DATASET/m-p/27708#M6347</link>
    <description>Hi:&lt;BR /&gt;
  You may have to look at a Macro program solution, then. The thing is that it looks like ODS OUTPUT does not collect the PCTLPTS info. And since you don't want PROC UNIVARIATE to put ALL your variables into one obs, you're going to have to make multiple passes through the data anyway.&lt;BR /&gt;
 &lt;BR /&gt;
I can get this output:&lt;BR /&gt;
[pre]&lt;BR /&gt;
after running macro program&lt;BR /&gt;
       &lt;BR /&gt;
Obs  varname   P_0   P_5  P_10  P_15  P_20  P_25  P_30  P_35  P_40  P_45  P_50   P_55   P_60   P_65   P_70   P_75   P_80  P_85  P_90  P_95  P_100&lt;BR /&gt;
           &lt;BR /&gt;
 1   age      11.0  11.0  11.0  12.0  12.0  12.0  12.0  12.0  13.0  13.0  13.0   14.0   14.0   14.0   14.0   15.0   15.0    15    15    16    16&lt;BR /&gt;
 2   height   51.3  51.3  56.3  56.5  57.3  57.5  59.0  59.8  62.5  62.5  62.8   63.5   64.3   64.8   65.3   66.5   66.5    67    69    72    72&lt;BR /&gt;
 3   weight   50.5  50.5  77.0  83.0  84.0  84.0  84.5  85.0  90.0  98.0  99.5  102.5  102.5  112.0  112.0  112.5  112.5   128   133   150   150&lt;BR /&gt;
   &lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
...by running the macro program below.&lt;BR /&gt;
&lt;BR /&gt;
You can automatically generate the macro calls (%dovars invocation) for each variable, if you know how to read the Dictionary tables, but for this example, I just hardcoded the values age, height and weight from SASHELP.CLASS.&lt;BR /&gt;
&lt;BR /&gt;
Hopefully, this will give you a place to start. The output above is from the final PROC PRINT on WORK.ALLQUANT.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
** 1) define the macro program;&lt;BR /&gt;
%macro dovars(indsn=, &lt;BR /&gt;
              myvar=,&lt;BR /&gt;
              del_prev=n);&lt;BR /&gt;
            &lt;BR /&gt;
** clear out work.allquant if requested;&lt;BR /&gt;
%if &amp;amp;del_prev = y %then %do;&lt;BR /&gt;
  proc datasets lib=work nodetails nofs nolist;&lt;BR /&gt;
    delete allquant;&lt;BR /&gt;
  run;&lt;BR /&gt;
  quit;&lt;BR /&gt;
%end;&lt;BR /&gt;
             &lt;BR /&gt;
** run proc univariate on the data specified;&lt;BR /&gt;
** for the variable specified;&lt;BR /&gt;
PROC UNIVARIATE DATA=&amp;amp;indsn;&lt;BR /&gt;
  VAR &amp;amp;myvar;&lt;BR /&gt;
  OUTPUT OUT=WORK.q_&amp;amp;myvar &lt;BR /&gt;
         PCTLPRE=P_ &lt;BR /&gt;
         PCTLPTS=0 to 100 by 5;&lt;BR /&gt;
RUN;&lt;BR /&gt;
                &lt;BR /&gt;
** create the VARNAME variable;&lt;BR /&gt;
data work.x;&lt;BR /&gt;
  length varname $32;&lt;BR /&gt;
  set work.q_&amp;amp;myvar;&lt;BR /&gt;
  varname = "&amp;amp;myvar";&lt;BR /&gt;
run;&lt;BR /&gt;
              &lt;BR /&gt;
** make the final dataset by adding;&lt;BR /&gt;
** this variable info to the prev runs;&lt;BR /&gt;
proc append base=work.allquant&lt;BR /&gt;
            data=work.x;&lt;BR /&gt;
run;&lt;BR /&gt;
             &lt;BR /&gt;
** clean up the work.x dataset;&lt;BR /&gt;
proc datasets lib=work nodetails nofs nolist;&lt;BR /&gt;
  delete x;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
         &lt;BR /&gt;
%mend dovars;&lt;BR /&gt;
           &lt;BR /&gt;
** 2) Use the macro program;&lt;BR /&gt;
%dovars(indsn=sashelp.class, myvar=age, del_prev=y);&lt;BR /&gt;
%dovars(indsn=sashelp.class, myvar=height, del_prev=n);&lt;BR /&gt;
%dovars(indsn=sashelp.class, myvar=weight, del_prev=n);&lt;BR /&gt;
             &lt;BR /&gt;
options nocenter nodate nonumber;&lt;BR /&gt;
proc print data=work.allquant;&lt;BR /&gt;
  title 'after running macro program';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Wed, 25 Jun 2008 21:08:27 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2008-06-25T21:08:27Z</dc:date>
    <item>
      <title>PROC UNIVARIATE PERCENTILES BY VARIABLE IN OUTPUT DATASET</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-UNIVARIATE-PERCENTILES-BY-VARIABLE-IN-OUTPUT-DATASET/m-p/27707#M6346</link>
      <description>OK,  The basic idea is to run PROC UNI like this&lt;BR /&gt;
&lt;BR /&gt;
PROC UNIVARIATE DATA=WORK.RECV_GL_CLEAN;&lt;BR /&gt;
 VAR A;&lt;BR /&gt;
 OUTPUT OUT=WORK.QUANTILES PCTLPRE=P_ PCTLPTS=0 to 100 by 5;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
I know I can put another var on the VAR line, but I get 20 additional columns for each variable I have.&lt;BR /&gt;
&lt;BR /&gt;
I need to do this on 500+ variables [long story]&lt;BR /&gt;
&lt;BR /&gt;
What I really want is an output data set like this:&lt;BR /&gt;
&lt;BR /&gt;
VAR_NAME P_0 P_5 ... P_100&lt;BR /&gt;
...&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
Where each observation is the variable name followed by the percentiles.&lt;BR /&gt;
&lt;BR /&gt;
I tried an ODS solution but the QUANTILES object doesn't look at the PCTLPTS paramters it only holds the default one.&lt;BR /&gt;
&lt;BR /&gt;
I also tried using PROC MEANS but I can't figure out how to specify PCTLPTS in PROC MEANS.&lt;BR /&gt;
&lt;BR /&gt;
Any ideas?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Ike</description>
      <pubDate>Wed, 25 Jun 2008 19:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-UNIVARIATE-PERCENTILES-BY-VARIABLE-IN-OUTPUT-DATASET/m-p/27707#M6346</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-06-25T19:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: PROC UNIVARIATE PERCENTILES BY VARIABLE IN OUTPUT DATASET</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-UNIVARIATE-PERCENTILES-BY-VARIABLE-IN-OUTPUT-DATASET/m-p/27708#M6347</link>
      <description>Hi:&lt;BR /&gt;
  You may have to look at a Macro program solution, then. The thing is that it looks like ODS OUTPUT does not collect the PCTLPTS info. And since you don't want PROC UNIVARIATE to put ALL your variables into one obs, you're going to have to make multiple passes through the data anyway.&lt;BR /&gt;
 &lt;BR /&gt;
I can get this output:&lt;BR /&gt;
[pre]&lt;BR /&gt;
after running macro program&lt;BR /&gt;
       &lt;BR /&gt;
Obs  varname   P_0   P_5  P_10  P_15  P_20  P_25  P_30  P_35  P_40  P_45  P_50   P_55   P_60   P_65   P_70   P_75   P_80  P_85  P_90  P_95  P_100&lt;BR /&gt;
           &lt;BR /&gt;
 1   age      11.0  11.0  11.0  12.0  12.0  12.0  12.0  12.0  13.0  13.0  13.0   14.0   14.0   14.0   14.0   15.0   15.0    15    15    16    16&lt;BR /&gt;
 2   height   51.3  51.3  56.3  56.5  57.3  57.5  59.0  59.8  62.5  62.5  62.8   63.5   64.3   64.8   65.3   66.5   66.5    67    69    72    72&lt;BR /&gt;
 3   weight   50.5  50.5  77.0  83.0  84.0  84.0  84.5  85.0  90.0  98.0  99.5  102.5  102.5  112.0  112.0  112.5  112.5   128   133   150   150&lt;BR /&gt;
   &lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
...by running the macro program below.&lt;BR /&gt;
&lt;BR /&gt;
You can automatically generate the macro calls (%dovars invocation) for each variable, if you know how to read the Dictionary tables, but for this example, I just hardcoded the values age, height and weight from SASHELP.CLASS.&lt;BR /&gt;
&lt;BR /&gt;
Hopefully, this will give you a place to start. The output above is from the final PROC PRINT on WORK.ALLQUANT.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
** 1) define the macro program;&lt;BR /&gt;
%macro dovars(indsn=, &lt;BR /&gt;
              myvar=,&lt;BR /&gt;
              del_prev=n);&lt;BR /&gt;
            &lt;BR /&gt;
** clear out work.allquant if requested;&lt;BR /&gt;
%if &amp;amp;del_prev = y %then %do;&lt;BR /&gt;
  proc datasets lib=work nodetails nofs nolist;&lt;BR /&gt;
    delete allquant;&lt;BR /&gt;
  run;&lt;BR /&gt;
  quit;&lt;BR /&gt;
%end;&lt;BR /&gt;
             &lt;BR /&gt;
** run proc univariate on the data specified;&lt;BR /&gt;
** for the variable specified;&lt;BR /&gt;
PROC UNIVARIATE DATA=&amp;amp;indsn;&lt;BR /&gt;
  VAR &amp;amp;myvar;&lt;BR /&gt;
  OUTPUT OUT=WORK.q_&amp;amp;myvar &lt;BR /&gt;
         PCTLPRE=P_ &lt;BR /&gt;
         PCTLPTS=0 to 100 by 5;&lt;BR /&gt;
RUN;&lt;BR /&gt;
                &lt;BR /&gt;
** create the VARNAME variable;&lt;BR /&gt;
data work.x;&lt;BR /&gt;
  length varname $32;&lt;BR /&gt;
  set work.q_&amp;amp;myvar;&lt;BR /&gt;
  varname = "&amp;amp;myvar";&lt;BR /&gt;
run;&lt;BR /&gt;
              &lt;BR /&gt;
** make the final dataset by adding;&lt;BR /&gt;
** this variable info to the prev runs;&lt;BR /&gt;
proc append base=work.allquant&lt;BR /&gt;
            data=work.x;&lt;BR /&gt;
run;&lt;BR /&gt;
             &lt;BR /&gt;
** clean up the work.x dataset;&lt;BR /&gt;
proc datasets lib=work nodetails nofs nolist;&lt;BR /&gt;
  delete x;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
         &lt;BR /&gt;
%mend dovars;&lt;BR /&gt;
           &lt;BR /&gt;
** 2) Use the macro program;&lt;BR /&gt;
%dovars(indsn=sashelp.class, myvar=age, del_prev=y);&lt;BR /&gt;
%dovars(indsn=sashelp.class, myvar=height, del_prev=n);&lt;BR /&gt;
%dovars(indsn=sashelp.class, myvar=weight, del_prev=n);&lt;BR /&gt;
             &lt;BR /&gt;
options nocenter nodate nonumber;&lt;BR /&gt;
proc print data=work.allquant;&lt;BR /&gt;
  title 'after running macro program';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 25 Jun 2008 21:08:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-UNIVARIATE-PERCENTILES-BY-VARIABLE-IN-OUTPUT-DATASET/m-p/27708#M6347</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-06-25T21:08:27Z</dc:date>
    </item>
  </channel>
</rss>

