<?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 freq one way table for multiple vars- export to data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924665#M363955</link>
    <description>&lt;P&gt;Why? Because that the way SAS programmed it, the output data set is only for the first variable. I don't know why they made that decision.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you can use ODS OUTPUT to get all the frequencies in one humongous ginormous table, that isn't particularly easy to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output onewayfreqs=outputdatasetname;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Apr 2024 10:33:42 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-04-17T10:33:42Z</dc:date>
    <item>
      <title>proc freq one way table for multiple vars- export to data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924663#M363954</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to run proc freq for all numeric variables.&lt;/P&gt;
&lt;P&gt;I want to export it to a data set and not print it.&lt;/P&gt;
&lt;P&gt;In this code I see the distribution only for one variable. Why??&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.class noprint;
tables _numeric_/ out=want (drop = percent);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Apr 2024 10:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924663#M363954</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-04-17T10:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq one way table for multiple vars- export to data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924665#M363955</link>
      <description>&lt;P&gt;Why? Because that the way SAS programmed it, the output data set is only for the first variable. I don't know why they made that decision.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you can use ODS OUTPUT to get all the frequencies in one humongous ginormous table, that isn't particularly easy to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output onewayfreqs=outputdatasetname;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 10:33:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924665#M363955</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-17T10:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq one way table for multiple vars- export to data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924666#M363956</link>
      <description>&lt;P&gt;If you are trying to determine unique number of levels for each variable, you want to use the NLEVELS option of PROC FREQ. Although as I said, number of unique levels for numeric variables isn't particularly meaningful in most cases.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 11:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924666#M363956</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-17T11:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq one way table for multiple vars- export to data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924671#M363958</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;This code provide output that is not comfortable to read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output onewayfreqs=want; 
proc freq data=sashelp.class;
tables age height weight;
run;
ods output close;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is the required output.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq noprint data = sashelp.class; 
tables age / out = data_age 
(rename = (age = category)); 
run;
proc freq noprint data = sashelp.class; 
tables height / out = data_height 
(rename = (height = category )); 
run;
proc freq noprint data = sashelp.class; 
tables weight / out = data_weight 
(rename = (weight = category )); 
run;

proc sort data = data_age; by category; run;
proc sort data = data_height; by category; run;
proc sort data = data_weight; by category; run;
data want;
retain Var_name;
set data_age data_height data_weight indsname = source;
dsname = scan(source,2,'.');  /* extract the data set name */
Var_name=substr(dsname,6);
drop dsname;
run;


 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to create it via one proc freq?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 11:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924671#M363958</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-04-17T11:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq one way table for multiple vars- export to data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924675#M363960</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Is there a way to create it via one proc freq?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Not that I know of.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Have you looked at the NLEVELS option?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 11:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924675#M363960</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-17T11:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq one way table for multiple vars- export to data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924676#M363961</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After preparing an intermediate dataset with PROC TRANSPOSE and PROC SORT you can obtain the desired output dataset with one PROC FREQ step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.class out=tmp(drop=name rename=(col1=category)) name=Var_name;
by name;
run;

proc sort data=tmp;
by Var_name;
run;

proc freq data=tmp noprint;
by Var_name;
tables category / out=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Apr 2024 11:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924676#M363961</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-04-17T11:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq one way table for multiple vars- export to data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924695#M363966</link>
      <description>&lt;P&gt;Learning point: Proc Freq supports multiple Tables statements.&lt;/P&gt;
&lt;P&gt;If you think you must do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;proc freq noprint data = sashelp.class; 
tables age / out = data_age 
(rename = (age = category)); 
run;
proc freq noprint data = sashelp.class; 
tables height / out = data_height 
(rename = (height = category )); 
run;
proc freq noprint data = sashelp.class; 
tables weight / out = data_weight 
(rename = (weight = category )); 
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That can be replaced with:&lt;/P&gt;
&lt;PRE&gt;proc freq noprint data = sashelp.class; 
   tables age / out = data_age 
                  (rename = (age = category)); 
   tables height / out = data_height 
                  (rename = (height = category )); 
   tables weight / out = data_weight 
                  (rename = (weight = category )); 
run;&lt;/PRE&gt;
&lt;P&gt;But I would say lack of imagination to say the ODS output "is not comfortable to read".&lt;/P&gt;
&lt;P&gt;And to get something that looks a bit like your mashed together example (but without creating 100 data sets)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ods output onewayfreqs=tempfreq; 
proc freq data=sashelp.class;
tables age height weight;
run;

data want;
   set tempfreq;
   length var_name $ 32 Category $ 16;
   Category = cats(of F_:);
   var_name = scan(table,2);
   keep var_name category Frequency percent;
run;&lt;/PRE&gt;
&lt;P&gt;If you look in the ODS set you will find two "versions" of each variable. The original variable and one that has "F_" prefixed to the name. That is for the formatted version of the variable and is a character value.&lt;/P&gt;
&lt;P&gt;Each observation will only have one of the F_ variables populated. So you can select the "category" using the CATS function with the list of F_: to use all those formatted values. You may ask why to use the F_ instead of the raw variable. Consider what happens if you have multiple (and especially custom formats) assigned to those numeric variables. If you create a single variable, like your "category" with those values what FORMAT would you assign? Nothing like trying to actually read a bunch of numbers that were a mixture of Date, Datetime, Currency and some other measurements and make sense of all the values with a single format assigned. Use of the F_ variables removes that headache. You could use a Max(list) but you will find, unless you spent a some time on your variable names, some issues with getting a simple list that works. Remember that the frequency and percentage variables will be numeric so you can't use the _numeric_ list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the percentages and the cumulative frequency values I would suggest changing the default variable names as the "percentage of what" and "Cumulative of what" have sort of changed. A long descriptive Label on those variables would be a good idea as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Table variable has the text "Table Varname". So you can pull the variable name quite easily from the Table variable.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 13:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924695#M363966</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-13T13:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq one way table for multiple vars- export to data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924730#M363982</link>
      <description>&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/e0903d269d4a71316a4e" target="_blank"&gt;https://gist.github.com/statgeek/e0903d269d4a71316a4e&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Run frequency for tables;
ods table onewayfreqs=temp;
proc freq data=sashelp.class;
	table _numeric_;
run;

*Format output;
data want;
length variable $32. variable_value $50.;
set temp;
Variable=scan(table, 2);

Variable_Value=strip(trim(vvaluex(variable)));

keep variable variable_value frequency percent cum:;
label variable='Variable' 
	variable_value='Variable Value';
run;

*Display;
proc print data=want(obs=20) label;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to run proc freq for all numeric variables.&lt;/P&gt;
&lt;P&gt;I want to export it to a data set and not print it.&lt;/P&gt;
&lt;P&gt;In this code I see the distribution only for one variable. Why??&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.class noprint;
tables _numeric_/ out=want (drop = percent);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 16:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/924730#M363982</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-04-17T16:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq one way table for multiple vars- export to data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/932079#M366679</link>
      <description>&lt;P&gt;The usage of CATS() is very tricky, I used to use COALESCEC() in there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Update: After trying, I think CATT() maybe better than CATS() in this condition, avoid to remove leading space of category.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 03:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-one-way-table-for-multiple-vars-export-to-data-set/m-p/932079#M366679</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2024-06-13T03:36:41Z</dc:date>
    </item>
  </channel>
</rss>

