<?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 to keep all variables from orginal dataset when using proc freq output datset? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599946#M173289</link>
    <description>&lt;P&gt;The OUT= option on a table statement will only do one table request. If you have multiple variables you would need one table statement per variable.&lt;/P&gt;
&lt;P&gt;OR&lt;/P&gt;
&lt;P&gt;Use other options that will create data sets that have different structures:&lt;/P&gt;
&lt;PRE&gt;proc freq data=sashelp.class;
ods output onewayfreqs= work.freqs;
table sex age ;
run;

proc tabulate data=sashelp.class out=work.tabulate;
   class sex age;
   table sex age,
         n pctn;
run;&lt;/PRE&gt;
&lt;P&gt;I just used two variables from a data set you should have so that you could examine the output for the data set structures. In most cases the Proc Tabulate approach may need the option /missing on the class statement as any record with a missing class variable will be excluded. In which case the percentages will be different that Proc Freq will produce for one-way tables.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Oct 2019 15:31:34 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-10-29T15:31:34Z</dc:date>
    <item>
      <title>How to keep all variables from orginal dataset when using proc freq output datset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599846#M173236</link>
      <description>&lt;P&gt;Hi SAS gurus,&lt;/P&gt;&lt;P&gt;I am having a problem using proc freq out= to generate a new dataset. I have 5 variables in the original dataset (Dummy) and I am using sas proc freq procedure to generate some frequency counts and generate a new dataset, but also want to have all 5 variables from the original dataset 'Dummy' into this new dataset egenrated by using proc freq out option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ex. my original dataset has&lt;/P&gt;&lt;P&gt;Name, Gender, County, Race, Address&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;after using proc freq data=dummy; tables gender/out=test; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will have only Gender (male/Female, Freq, Percent, CumFreq, CumPercent) in 'test' dataset. But I want Gender, Race, Address, County and Name along with Freq and Percent from the test dataset. So the new dataset 'test' should have 5+2 variables in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much,&lt;/P&gt;&lt;P&gt;Malathi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 15:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599846#M173236</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2019-10-28T15:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep all variables from orginal dataset when using proc freq output datset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599850#M173238</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91804"&gt;@Malathi13&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show us the proc freq code that you are using.&amp;nbsp; Without seeing it, I suspect you can solve the problem by specifying a five-way TABLES statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 16:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599850#M173238</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-28T16:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep all variables from orginal dataset when using proc freq output datset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599933#M173283</link>
      <description>&lt;P&gt;Just tell PROC FREQ that you want to use all of the variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;tables Name*Gender*County*Race*Address / out=test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Are you sure you won't end up with count of 1 for every combination?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 20:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599933#M173283</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-28T20:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep all variables from orginal dataset when using proc freq output datset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599946#M173289</link>
      <description>&lt;P&gt;The OUT= option on a table statement will only do one table request. If you have multiple variables you would need one table statement per variable.&lt;/P&gt;
&lt;P&gt;OR&lt;/P&gt;
&lt;P&gt;Use other options that will create data sets that have different structures:&lt;/P&gt;
&lt;PRE&gt;proc freq data=sashelp.class;
ods output onewayfreqs= work.freqs;
table sex age ;
run;

proc tabulate data=sashelp.class out=work.tabulate;
   class sex age;
   table sex age,
         n pctn;
run;&lt;/PRE&gt;
&lt;P&gt;I just used two variables from a data set you should have so that you could examine the output for the data set structures. In most cases the Proc Tabulate approach may need the option /missing on the class statement as any record with a missing class variable will be excluded. In which case the percentages will be different that Proc Freq will produce for one-way tables.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 15:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599946#M173289</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-29T15:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep all variables from orginal dataset when using proc freq output datset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599962#M173298</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91804"&gt;@Malathi13&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Looks like you just want to remerge your frequencies back with the original data by gender. There're gobs of ways to do it after proc FREQ is done. Here's one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                             
  input gender $ name $ age ;                                                                                                           
  cards ;                                                                                                                               
M  Alfred  14                                                                                                                           
F  Barbara 13                                                                                                                           
F  Carol   14                                                                                                                           
F  Jane    12                                                                                                                           
F  Janet   15                                                                                                                           
M  Jeffrey 13                                                                                                                           
M  John    12                                                                                                                           
F  Judy    14                                                                                                                           
F  Mary    15                                                                                                                           
M  Robert  12                                                                                                                           
;                                                                                                                                       
run ;                                                                                                                                   
                                                                                                                                        
proc freq data = have noprint ;                                                                                                         
  tables gender / out = freq (index=(gender)) outcum ;                                                                                  
run ;                                                                                                                                   
                                                                                                                                        
data want ;                                                                                                                             
  set have ;                                                                                                                            
  set freq key = gender / unique ;                                                                                                      
run ;                                 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 01:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599962#M173298</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-29T01:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep all variables from orginal dataset when using proc freq output datset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599991#M173312</link>
      <description>&lt;P&gt;SQL?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
  a.*,
  count(sex) as count_sex,
  calculated count_sex / (select count(*) from sashelp.class) as percent_sex format=percent8.2
from sashelp.class a
group by sex
order by name;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maybe more performant, but needs an extra step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select nobs into :nobs from dictionary.tables
where libname = 'SASHELP' and memname = 'CLASS';
create table want as
select
  a.*,
  count(sex) as count_sex,
  calculated count_sex / &amp;amp;nobs as percent_sex format=percent8.2
from sashelp.class a
group by sex
order by name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Oct 2019 06:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/599991#M173312</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-29T06:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep all variables from orginal dataset when using proc freq output datset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/600003#M173320</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Both are fine, and the extra step for extra performance is more than well justified - after all, the performance penalty of getting stuff from the dictionary tables is next to nil.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only problem is, due to the nature of the SQL's "no concept of row sequence", it can't give you the cumulatives. If I were tasked with doing the whole enchilada in a single step, I'd most likely resort to a hash. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                             
  input gender $ name $ age ;                                                                                                           
  cards ;                                                                                                                               
M  Alfred  14                                                                                                                           
F  Barbara 13                                                                                                                           
F  Carol   14                                                                                                                           
F  Jane    12                                                                                                                           
F  Janet   15                                                                                                                           
M  Jeffrey 13                                                                                                                           
M  John    12                                                                                                                           
F  Judy    14                                                                                                                           
F  Mary    15                                                                                                                           
M  Robert  12                                                                                                                           
;                                                                                                                                       
run ;                                                                                                                                   
                                                                                                                                        
data want ;                                                                                                                             
  dcl hash f () ;                                                                                                            
  f.definekey  ("gender") ;                                                                                                             
  f.definedata ("gender", "count") ;                                                                                                    
  f.definedone () ;                                                                                                                     
  dcl hiter fi ("f") ;                                                                                                                  
                                                                                                                                        
  dcl hash q () ;                                                                                                            
  q.definekey  ("gender") ;                                                                                                             
  q.definedata ("count", "cum_freq", "cum_pct") ;                                                                                       
  q.definedone () ;                                                                                                                     
                                                                                                                                        
  do until (z1) ;                                                                                                                       
    set have end = z1 nobs = n ;                                                                                                        
    if f.find() ne 0 then count = 1 ;                                                                                                   
    else                  count + 1 ;                                                                                                   
    f.replace() ;                                                                                                                       
  end ;                                                                                                                                 
                                                                                                                                        
  do while (fi.next() = 0) ;                                                                                                            
    pct = 100 * divide (count, n) ;                                                                                                     
    cum_freq  + count ;                                                                                                                 
    cum_pct + pct ;                                                                                                                     
    q.add() ;                                                                                                                           
  end ;                                                                                                                                 
                                                                                                                                        
  do until (z2) ;                                                                                                                       
    set have end = z2 ;                                                                                                                 
    q.find() ;                                                                                                                          
    output ;                                                                                                                            
  end ;                                                                                                                                 
run ;                                  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, I have to admit that though it takes a hash man but a few minutes to code it, in the real world I'd rather stick to FREQ and backward merge, especially since in the case of gender, the FREQ output data set has only 2 records, anyway. Plus, FREQ gives me everything I need basically just by aping rather than programming, so why bother? Not to mention those going on to cannibalize on my code who aren't exactly hash men.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 08:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-all-variables-from-orginal-dataset-when-using-proc/m-p/600003#M173320</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-29T08:26:12Z</dc:date>
    </item>
  </channel>
</rss>

