<?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 output multiple variables from proc freq into a dataset? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70844#M20401</link>
    <description>Ksharp,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your code. Before I'll try it, I have a question:&lt;BR /&gt;
catx(' ',of name--weight) - looks like this function captures missing character values while I need zero numeric ones. Do I change the code like catx(0,of name--weight)?&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
corella</description>
    <pubDate>Mon, 30 May 2011 17:14:45 GMT</pubDate>
    <dc:creator>corella</dc:creator>
    <dc:date>2011-05-30T17:14:45Z</dc:date>
    <item>
      <title>How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70836#M20393</link>
      <description>Hello!&lt;BR /&gt;
&lt;BR /&gt;
I cannot figure out how to output results of proc freq on multiple variables into a SAS dataset. Proc freq can capture only the last variable listed in tables. I tried Proc summary but to no avail. I need to output the frequency of zero values into a dataset rather than having a huge .lst file because my original dataset has 399 variables and 1,700,000 records. I created a custom format for zero numeric values:&lt;BR /&gt;
proc format;&lt;BR /&gt;
value num_zero&lt;BR /&gt;
0='ZERO'&lt;BR /&gt;
other='NON-ZERO;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
Where do I go from this?&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance if you can help me.&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: corella</description>
      <pubDate>Fri, 27 May 2011 19:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70836#M20393</guid>
      <dc:creator>corella</dc:creator>
      <dc:date>2011-05-27T19:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70837#M20394</link>
      <description>Hi:&lt;BR /&gt;
  Consider using the ODS OUTPUT statement.&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods output onewayfreqs=work.owf;&lt;BR /&gt;
proc freq data=sashelp.class;&lt;BR /&gt;
  tables age sex;&lt;BR /&gt;
run;&lt;BR /&gt;
       &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=work.owf;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
produces this output in the WORK.OWF dataset:&lt;BR /&gt;
[pre]&lt;BR /&gt;
                                                               Cum         Cum&lt;BR /&gt;
Obs      Table      F_Age    Age    Frequency    Percent    Frequency    Percent    F_Sex    Sex&lt;BR /&gt;
&lt;BR /&gt;
 1     Table Age     11       11           2      10.53            2      10.53&lt;BR /&gt;
 2     Table Age     12       12           5      26.32            7      36.84&lt;BR /&gt;
 3     Table Age     13       13           3      15.79           10      52.63&lt;BR /&gt;
 4     Table Age     14       14           4      21.05           14      73.68&lt;BR /&gt;
 5     Table Age     15       15           4      21.05           18      94.74&lt;BR /&gt;
 6     Table Age     16       16           1       5.26           19     100.00&lt;BR /&gt;
 7     Table Sex               .           9      47.37            9      47.37       F       F&lt;BR /&gt;
 8     Table Sex               .          10      52.63           19     100.00       M       M&lt;BR /&gt;
    [/pre]&lt;BR /&gt;
  &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 27 May 2011 19:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70837#M20394</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-05-27T19:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70838#M20395</link>
      <description>Hello Corella,&lt;BR /&gt;
&lt;BR /&gt;
You could try this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data i;&lt;BR /&gt;
  do i=1 to 100;&lt;BR /&gt;
    x=ROUND(RANUNI(12345));&lt;BR /&gt;
    y=ROUND(RANUNI(54321));&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;  &lt;BR /&gt;
run;&lt;BR /&gt;
data r (drop=i x--y);&lt;BR /&gt;
  set i end=e;&lt;BR /&gt;
  array a{*} x--y;&lt;BR /&gt;
  array a0{*} x1-x399; &lt;BR /&gt;
  do i=1 to DIM(a);&lt;BR /&gt;
    if a[i]=0 then a0[i]+1; &lt;BR /&gt;
  end;&lt;BR /&gt;
  if e then output;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Fri, 27 May 2011 19:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70838#M20395</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-27T19:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70839#M20396</link>
      <description>Thank you Cynthia, it worked 95%. I still need to make some adjustments to the dataset I received but in general your method did the job.&lt;BR /&gt;
&lt;BR /&gt;
Many thanks,&lt;BR /&gt;
corella</description>
      <pubDate>Fri, 27 May 2011 20:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70839#M20396</guid>
      <dc:creator>corella</dc:creator>
      <dc:date>2011-05-27T20:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70840#M20397</link>
      <description>SPR, I thought about creating a variable that would hold a rolled-up number of all zeros across the given row but I didn't know how to do that. I assume your code just does this. I want to use it, maybe not in this case but I have some difficulties to fully understand it. Would you please be so kind and add comments /* to each process because I don't want to just copy and paste, I want to understand what I am doing.&lt;BR /&gt;
&lt;BR /&gt;
Thank you&lt;BR /&gt;
corella</description>
      <pubDate>Fri, 27 May 2011 20:53:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70840#M20397</guid>
      <dc:creator>corella</dc:creator>
      <dc:date>2011-05-27T20:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70841#M20398</link>
      <description>[pre]&lt;BR /&gt;
 &lt;BR /&gt;
&lt;BR /&gt;
ods output onewayfreqs=work.owf;&lt;BR /&gt;
proc freq data=sashelp.class ;&lt;BR /&gt;
  tables _all_/nocum nopercent ;&lt;BR /&gt;
run;&lt;BR /&gt;
data work.owf(drop=frequency) ;&lt;BR /&gt;
 set work.owf ;&lt;BR /&gt;
 count=frequency;&lt;BR /&gt;
run;&lt;BR /&gt;
data work.owf;&lt;BR /&gt;
length v_name v_value $ 200;&lt;BR /&gt;
 set work.owf; &lt;BR /&gt;
 v_name=scan(table,2);&lt;BR /&gt;
 v_value=scan(catx(' ',of name--weight),1); &lt;BR /&gt;
 *name is the first variable,weight is the last variable in sashelp.class table;&lt;BR /&gt;
 keep v_name v_value count;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Mon, 30 May 2011 09:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70841#M20398</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-30T09:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70842#M20399</link>
      <description>Hello Corella,&lt;BR /&gt;
&lt;BR /&gt;
These are comments:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data r (drop=i x--y); /* drops variables from x to y from output dataset */&lt;BR /&gt;
  set i end=e; /* e=1 for the last obs of dataset i */&lt;BR /&gt;
  array a{*} x--y; /* This array contains all variables from x to y in the dataset  i */&lt;BR /&gt;
  array a0{*} x1-x399; /*This array contains variables from x1 to x399 for counts of zeros */ &lt;BR /&gt;
  do i=1 to DIM(a); /*DIM(a) is the number of variables in array a */&lt;BR /&gt;
    if a[i]=0 then a0[i]+1; /* counts zeros for every variable in array a and store them in a0 */;&lt;BR /&gt;
  end;&lt;BR /&gt;
  if e then output; /* outputs result when the last observation from i is precessed */&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Mon, 30 May 2011 14:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70842#M20399</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-30T14:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70843#M20400</link>
      <description>Thanks for the comments SPR. What confused me before what the usage of i for both the dataset and counter. I needed a confirmation that i in set i is not the same as in do i=1 or a&lt;I&gt;=0.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
corella&lt;/I&gt;</description>
      <pubDate>Mon, 30 May 2011 17:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70843#M20400</guid>
      <dc:creator>corella</dc:creator>
      <dc:date>2011-05-30T17:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70844#M20401</link>
      <description>Ksharp,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your code. Before I'll try it, I have a question:&lt;BR /&gt;
catx(' ',of name--weight) - looks like this function captures missing character values while I need zero numeric ones. Do I change the code like catx(0,of name--weight)?&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
corella</description>
      <pubDate>Mon, 30 May 2011 17:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70844#M20401</guid>
      <dc:creator>corella</dc:creator>
      <dc:date>2011-05-30T17:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70845#M20402</link>
      <description>It is OK. dataset and variable could have the same names.&lt;BR /&gt;
SPR</description>
      <pubDate>Mon, 30 May 2011 17:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70845#M20402</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-30T17:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70846#M20403</link>
      <description>Yes.can code like catx('0',of name--weight),&lt;BR /&gt;
But you need to test it by yourself.&lt;BR /&gt;
SAS is smart enough to filter the missing value . when you use "scan(catx(" ,sas will automatically fetch the first null missing value.But you need to process your dataset firstly.&lt;BR /&gt;
Like:&lt;BR /&gt;
data temp;&lt;BR /&gt;
 ....&lt;BR /&gt;
_weight=put(weight, myfmt.);&lt;BR /&gt;
.....&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Tue, 31 May 2011 00:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70846#M20403</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-31T00:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to output multiple variables from proc freq into a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70847#M20404</link>
      <description>Thank you Ksharp.</description>
      <pubDate>Wed, 01 Jun 2011 19:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-output-multiple-variables-from-proc-freq-into-a-dataset/m-p/70847#M20404</guid>
      <dc:creator>corella</dc:creator>
      <dc:date>2011-06-01T19:45:49Z</dc:date>
    </item>
  </channel>
</rss>

