<?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 Freq Results as Data Table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344373#M79133</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using proc freq to create a transition matrix. I'm getting the table I want in the results tab, but would like to have it output as a seperate data table as well. Here's the code I'm currently using to get the table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data = events_limited; 
tables start_bases_cd*end_bases_cd /outpct nopercent nocol nofreq;
Title 'Transitions';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and here's the results that I would like to be stored in a table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7957iD5DC6AFD93665CEA/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="sas_output.JPG" title="sas_output.JPG" width="683" height="238" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's the best way to acheive this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 26 Mar 2017 03:36:00 GMT</pubDate>
    <dc:creator>jl1005</dc:creator>
    <dc:date>2017-03-26T03:36:00Z</dc:date>
    <item>
      <title>Proc Freq Results as Data Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344373#M79133</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using proc freq to create a transition matrix. I'm getting the table I want in the results tab, but would like to have it output as a seperate data table as well. Here's the code I'm currently using to get the table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data = events_limited; 
tables start_bases_cd*end_bases_cd /outpct nopercent nocol nofreq;
Title 'Transitions';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and here's the results that I would like to be stored in a table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7957iD5DC6AFD93665CEA/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="sas_output.JPG" title="sas_output.JPG" width="683" height="238" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's the best way to acheive this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 03:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344373#M79133</guid>
      <dc:creator>jl1005</dc:creator>
      <dc:date>2017-03-26T03:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq Results as Data Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344380#M79135</link>
      <description>Without digging into your exact requirement, there are (at least) three possibilities to get output data:&lt;BR /&gt;- output statement &lt;BR /&gt;- out= option on the table statement &lt;BR /&gt;- the ODS data destination</description>
      <pubDate>Sun, 26 Mar 2017 05:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344380#M79135</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-03-26T05:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq Results as Data Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344382#M79136</link>
      <description>I've tried the out= option, but couldn't find a way to just return row percent. That's the only statistic I'd like in the final output.</description>
      <pubDate>Sun, 26 Mar 2017 05:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344382#M79136</guid>
      <dc:creator>jl1005</dc:creator>
      <dc:date>2017-03-26T05:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq Results as Data Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344386#M79138</link>
      <description>&lt;P&gt;You can use a KEEP on the output dataset to keep only the variables you care about.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tables.../out=want(keep = ...);&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 05:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344386#M79138</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-26T05:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq Results as Data Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344406#M79145</link>
      <description>&lt;P&gt;Add one more proc transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

proc freq data = sashelp.class noprint; 
tables sex*age / out=x outpct nopercent nocol nofreq ;
Title 'Transitions';
run;



proc transpose data=x out=want;
by sex;
id age;
var pct_row;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Mar 2017 10:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344406#M79145</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-26T10:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq Results as Data Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344426#M79154</link>
      <description>&lt;P&gt;Okay, so taking everyones advice, here what the code ended up looking like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data = events_limited;	
	tables start_bases_cd*end_bases_cd / out=transition outpct nopercent nocol nofreq;
	Title 'Transitions';
	run;
proc transpose data = transition out=transition_1;
	by start_bases_cd;
	id end_bases_cd;
	var pct_row;
	run;
proc stdize data =  transition_1 out = transition_2 reponly missing=0;
proc sql;
	create table transition_3 AS
	select start_bases_cd, '   0'n/100 as end_0 format D6.4, '   1'n/100 as end_1 format D6.4, '   2'n/100 as end_2 format D6.4, '   3'n/100 as end_3 format D6.4
		, '   4'n/100 as end_4 format D6.4, '   5'n/100 as end_5 format D6.4, '   6'n/100 as end_6 format D6.4, '   7'n/100 as end_7 format D6.4 
	from transition_2
	;
	quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The stdize was to insert 0's where the field was blank and the sql was to force the columns back in order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In regards to formatting and renaming the columns, is there a more efficient way to accomplish this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, in one field only theres a number written as scientific notation. Is there an easy way to force that to round to 0?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 17:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344426#M79154</guid>
      <dc:creator>jl1005</dc:creator>
      <dc:date>2017-03-26T17:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq Results as Data Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344432#M79155</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;I am still not sure what you mean by the original request that your report from PROC FREQ should be "stored in a table" -- do you really mean you want a SAS data set that looks "exactly" like the report you provided? Or, do you just want the report to be in a different format, such as in an Excel worksheet or in a Word doc?&lt;BR /&gt;&lt;BR /&gt;You did not really define what you want other than to say "stored in a table" -- but did not provide more information about the ultimate usage of a table that stores a report. While there are many convoluted ways to take your report and get it into a dataset, there are many easier ways to make a Word doc or an Excel sheet out of this data. Can you elaborate on what the final usage of this table will be?&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;cynthia&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 18:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344432#M79155</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-03-26T18:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq Results as Data Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344493#M79172</link>
      <description>&lt;P&gt;I think you want a file with one row per START_BASES_CD and one var per value of END_BASES_CD.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data = events_limited; 
  tables start_bases_cd*end_bases_cd / noprint sparse out=need1a;
  tables start_bases_cd /noprint out=need1b;
run;

data want;
   merge need1a  need1b (rename=(count=row_total));
   by start_bases_cd;
   array  pct {0:7} percent_0-percent_7;
   retain percent_:;
   if first.start_bases_cd then call missing(of pct{*});
   pct{end_bases_cd}=100*count/row_total;
   drop percent count row_total end_bases_cd;
   if last.start_bases_cd;
 run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;t uses proc freq to make&amp;nbsp; two output data&amp;nbsp; sets, one with counts of each start/end combination, and one with total counts for each start value. Then the second step merges them and generates the percent vars.&amp;nbsp; Note this program assumes you really do have codes=0,1,2,...7.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't have exact codes 0 through 7, this next program will handle the general case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data = events_limited; 
  tables start_bases_cd*end_bases_cd / noprint sparse out=need1a;
  tables start_bases_cd /noprint out=need1b;
run;

data  need2;
  merge need1a  need1b (rename=(count=row_total));
  by start_bases_cd;
  percent=100*count/row_total;
  drop count row_total;
run;

proc transpose data=need2 out=want2 (drop=_name_ _label_) prefix=percent_;
  by start_bases_cd;
  var percent;
  id end_bases_cd;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This one&amp;nbsp;starts with the same PROC FREQ.&amp;nbsp; It merges the two data sets and lets proc transpose name the resulting variables.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 02:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344493#M79172</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-27T02:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq Results as Data Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344834#M79281</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially I wanted to results I had posted above in a picture to be stored exactly as is, or at least very close to that in a SAS data set. Does that clear it up?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 23:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344834#M79281</guid>
      <dc:creator>jl1005</dc:creator>
      <dc:date>2017-03-27T23:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq Results as Data Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344835#M79282</link>
      <description>&lt;P&gt;The first code you posted worked perfectly, thank you. It's much more efficient than what I had come up with.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 23:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-Results-as-Data-Table/m-p/344835#M79282</guid>
      <dc:creator>jl1005</dc:creator>
      <dc:date>2017-03-27T23:54:14Z</dc:date>
    </item>
  </channel>
</rss>

