<?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 Proc Tabulate : out= default variable name issue in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-out-default-variable-name-issue/m-p/66128#M18862</link>
    <description>Is there a method for the user to define variable names within the output dataset?&lt;BR /&gt;
The below code is part of a production process in my workplace. &lt;BR /&gt;
The variable name length of the macro variable &amp;amp;score is between 23 to 28. &lt;BR /&gt;
The tabulate procedure defaults the variable names for the computed stats within the DecileOut dataset(var_stat ..score_mean score_min score_max). &lt;BR /&gt;
When the combined variable name (&amp;amp;score_mean) is greater then 32, SAS defaults the variable name to 'Mean'. I am aware that the variable name length is limited to 32. &lt;BR /&gt;
So my question: Can a user define variable names within the Output dataset in Proc Tabulate? Please provide examples. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc tabulate data=temp2 noseps formchar='           ' out=DecileOut;&lt;BR /&gt;
    class r_score;&lt;BR /&gt;
    var &amp;amp;score ;&lt;BR /&gt;
    weight weight;&lt;BR /&gt;
    table r_one='' all,&lt;BR /&gt;
          &amp;amp;score*(min mean max)*f=percent8.2&lt;BR /&gt;
    ;&lt;BR /&gt;
  run;</description>
    <pubDate>Tue, 16 Dec 2008 15:57:28 GMT</pubDate>
    <dc:creator>mav08</dc:creator>
    <dc:date>2008-12-16T15:57:28Z</dc:date>
    <item>
      <title>Proc Tabulate : out= default variable name issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-out-default-variable-name-issue/m-p/66128#M18862</link>
      <description>Is there a method for the user to define variable names within the output dataset?&lt;BR /&gt;
The below code is part of a production process in my workplace. &lt;BR /&gt;
The variable name length of the macro variable &amp;amp;score is between 23 to 28. &lt;BR /&gt;
The tabulate procedure defaults the variable names for the computed stats within the DecileOut dataset(var_stat ..score_mean score_min score_max). &lt;BR /&gt;
When the combined variable name (&amp;amp;score_mean) is greater then 32, SAS defaults the variable name to 'Mean'. I am aware that the variable name length is limited to 32. &lt;BR /&gt;
So my question: Can a user define variable names within the Output dataset in Proc Tabulate? Please provide examples. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc tabulate data=temp2 noseps formchar='           ' out=DecileOut;&lt;BR /&gt;
    class r_score;&lt;BR /&gt;
    var &amp;amp;score ;&lt;BR /&gt;
    weight weight;&lt;BR /&gt;
    table r_one='' all,&lt;BR /&gt;
          &amp;amp;score*(min mean max)*f=percent8.2&lt;BR /&gt;
    ;&lt;BR /&gt;
  run;</description>
      <pubDate>Tue, 16 Dec 2008 15:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-out-default-variable-name-issue/m-p/66128#M18862</guid>
      <dc:creator>mav08</dc:creator>
      <dc:date>2008-12-16T15:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate : out= default variable name issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-out-default-variable-name-issue/m-p/66129#M18863</link>
      <description>Hi:&lt;BR /&gt;
  You can always use RENAME=(old=new) Data set option when creating output datasets. That can be used most places you can specify a OUT= dataset.&lt;BR /&gt;
 &lt;BR /&gt;
  I'd recommend 2 possibilities&lt;BR /&gt;
1) taking all the vowels out of the &amp;amp;SCORE macro variable to make a new variable name with the stats appended or (this is a good approach, if you have numbered variables with the numbers out at position 27 or 28 of the name)&lt;BR /&gt;
2) take the first 25 or 26 characters of the &amp;amp;SCORE macro variable to make a new variable name (this is a good approach if your variable names are unique in the first 25 or 26 characters and if your stat name plus an underscore is not more than 6 characters.)&lt;BR /&gt;
                      &lt;BR /&gt;
  I show an example below. If the &amp;amp;SCORE macro variable is less than 26, then you'll get the whole value. Note that in my code, I use &amp;amp;NEW in the RENAME statement and not &amp;amp;ALTNEW.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
           &lt;BR /&gt;
ps OK, if you know macro processing, you know that I could make the code below WAY more complicated and automated with conditional %IF logic, etc in a macro program. But I wanted to keep this simple and something that didn't require a macro program.&lt;BR /&gt;
       &lt;BR /&gt;
[pre]&lt;BR /&gt;
%let score = inventory;&lt;BR /&gt;
%let new = %sysfunc(compress(&amp;amp;score,aeiou,i));&lt;BR /&gt;
%let altnew = %substr(&amp;amp;score,1,26);&lt;BR /&gt;
                                  &lt;BR /&gt;
%put original variable name = &amp;amp;score;&lt;BR /&gt;
%put variable name without vowels = &amp;amp;new;&lt;BR /&gt;
%put alternate name shortened to 26 chars = &amp;amp;altnew;&lt;BR /&gt;
                   &lt;BR /&gt;
                   &lt;BR /&gt;
proc tabulate data=sashelp.shoes &lt;BR /&gt;
              out=DecileOut(rename=(&amp;amp;score._min=&amp;amp;new._min&lt;BR /&gt;
                                    &amp;amp;score._mean=&amp;amp;new._mean&lt;BR /&gt;
                                    &amp;amp;score._max=&amp;amp;new._max));&lt;BR /&gt;
class region product;&lt;BR /&gt;
var &amp;amp;score ;&lt;BR /&gt;
table product='' all,&lt;BR /&gt;
      &amp;amp;score*(min mean max);&lt;BR /&gt;
run; &lt;BR /&gt;
                                &lt;BR /&gt;
proc print data=DecileOut;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 16 Dec 2008 18:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-out-default-variable-name-issue/m-p/66129#M18863</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-12-16T18:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate : out= default variable name issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-out-default-variable-name-issue/m-p/66130#M18864</link>
      <description>Thanks Cynthia.&lt;BR /&gt;
However this solution does not work. SAS errors out on the rename step. &lt;BR /&gt;
Below is the log.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
             24         Mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_mean&lt;BR /&gt;
           _________________________________&lt;BR /&gt;
           213&lt;BR /&gt;
ERROR 213-322: Variable name Mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_mean is longer than 32 characters.&lt;BR /&gt;
 &lt;BR /&gt;
NOTE 138-205: Line generated by the macro variable "PREBAD".&lt;BR /&gt;
24         Mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_mean&lt;BR /&gt;
           _________________________________&lt;BR /&gt;
           23&lt;BR /&gt;
ERROR 23-7: Invalid value for the RENAME option.</description>
      <pubDate>Tue, 16 Dec 2008 19:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-out-default-variable-name-issue/m-p/66130#M18864</guid>
      <dc:creator>mav08</dc:creator>
      <dc:date>2008-12-16T19:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate : out= default variable name issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-out-default-variable-name-issue/m-p/66131#M18865</link>
      <description>Hi:&lt;BR /&gt;
  Ah, yes, my bad. I didn't run into that issue with "INVENTORY" as the variable. So, the error comes from the &amp;amp;score._min, etc -- which means you have to use the statistic names in the OUT=.  For more complicated logic, you might need a macro program or you just might need a datastep to rename your variables before the tabulate runs, so you have more reliable (and smaller) variable names.&lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
My (partial) output:&lt;BR /&gt;
[pre]&lt;BR /&gt;
decileout2 -- substring method&lt;BR /&gt;
&lt;BR /&gt;
                                                        supercalifragilistic_    supercalifragilistic_    supercalifragilistic_&lt;BR /&gt;
Obs    Product           _TYPE_    _PAGE_    _TABLE_             min                      mean                     max&lt;BR /&gt;
                                                 &lt;BR /&gt;
 1     Boot                1          1         1                 374                  187012.90                  882080&lt;BR /&gt;
 2     Men's Casual        1          1         1                2176                  379672.29                 2881005&lt;BR /&gt;
 3     Men's Dress         1          1         1                 538                  290146.80                 1847559&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                              &lt;BR /&gt;
My revised code:&lt;BR /&gt;
[pre]&lt;BR /&gt;
options nodate nonumber nocenter ls=180;&lt;BR /&gt;
data testdata;&lt;BR /&gt;
  set sashelp.shoes;&lt;BR /&gt;
  supercalifragilisticexpeialidoci = inventory;&lt;BR /&gt;
run;&lt;BR /&gt;
                             &lt;BR /&gt;
%let score = supercalifragilisticexpeialidoci;&lt;BR /&gt;
%let new = %substr(&amp;amp;score,1,20);&lt;BR /&gt;
                   &lt;BR /&gt;
proc tabulate data=testdata &lt;BR /&gt;
              out=DecileOut2(rename=(min=&amp;amp;new._min&lt;BR /&gt;
                                    mean=&amp;amp;new._mean&lt;BR /&gt;
                                    max=&amp;amp;new._max));&lt;BR /&gt;
class region product;&lt;BR /&gt;
var &amp;amp;score ;&lt;BR /&gt;
table product='' all,&lt;BR /&gt;
      &amp;amp;score*(min mean max);&lt;BR /&gt;
run; &lt;BR /&gt;
                                    &lt;BR /&gt;
proc print data=DecileOut2;&lt;BR /&gt;
  title 'decileout2 -- substring method';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                      &lt;BR /&gt;
Alternative -- just rename long variable and then you don't have to worry about it. You'd now use &amp;amp;NEW in the TABULATE step without having to do a RENAME in TABULATE:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let score = supercalifragilisticexpeialidoci;&lt;BR /&gt;
%let new = %substr(&amp;amp;score,1,20);&lt;BR /&gt;
                            &lt;BR /&gt;
data alt;&lt;BR /&gt;
  set testdata(rename=(&amp;amp;score=&amp;amp;new));&lt;BR /&gt;
run;&lt;BR /&gt;
                   &lt;BR /&gt;
proc tabulate data=alt &lt;BR /&gt;
              out=DecileOut3;&lt;BR /&gt;
class region product;&lt;BR /&gt;
var &amp;amp;new ;&lt;BR /&gt;
table product='' all,&lt;BR /&gt;
      &amp;amp;new*(min mean max);&lt;BR /&gt;
run; &lt;BR /&gt;
                           &lt;BR /&gt;
proc print data=DecileOut3 ;&lt;BR /&gt;
  title 'decileout3 different';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 16 Dec 2008 21:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-out-default-variable-name-issue/m-p/66131#M18865</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-12-16T21:21:41Z</dc:date>
    </item>
  </channel>
</rss>

