<?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: Outputting a Data Set Using Proc Freq That Gives Frequency of Responses for Categorical Variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574836#M12750</link>
    <description>&lt;P&gt;There are other approaches.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Transpose to a long format via PROC TRANSPOSE or a data step&lt;/P&gt;
&lt;P&gt;2. PROC FREQ for summary statistics same as above&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data is all there, it's just not show, the display is limited to 20 observations because of the (obs=20) data set option on the PROC PRINT statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/213376"&gt;@JackZ295&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, thanks for your help. Is there an easier way to do it? This seems rather complicated and not all of the variables show up.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jul 2019 00:58:23 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-07-19T00:58:23Z</dc:date>
    <item>
      <title>Outputting a Data Set Using Proc Freq That Gives Frequency of Responses for Categorical Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574820#M12746</link>
      <description>&lt;P&gt;Is there a way to find the frequency of all of the responses of several categorical variables and output this data in a new data set? The possible responses of each categorical variable are as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1: No, strongly disagree&lt;/P&gt;&lt;P&gt;2: No, somewhat disagree&lt;/P&gt;&lt;P&gt;3: Neither agree nor disagree&lt;/P&gt;&lt;P&gt;4: Yes, somewhat agree&lt;/P&gt;&lt;P&gt;5: Yes, strongly agree&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a sample data set that I would want to run a proc freq on:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; sample&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;id&lt;/SPAN&gt; A1Q1 A2Q1 RFQ1 SE1Q1 SE2Q1 SE3Q1 SE4Q1 I1Q1 I2Q1 I3Q1&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;1 2 1 1 3 3 4 2 5 3 2 
2 1 1 1 1 1 1 1 1 1 1
3 2 3 4 5 1 2 3 4 5 1 
4 1 2 3 4 5 5 4 3 2 1
5 1 1 1 1 1 1 1 1 1 1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After I do so, I would want to output the frequency of responses for each of these categorical variables in a new data set. Is there a way to do so? How would I do so for the following variables: A1Q1 A2Q1 RFQ1 SE1Q1 SE2Q1 SE3Q1 SE4Q1 I1Q1 I2Q1 I3QQ1 I4Q1 all in one new data set?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 22:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574820#M12746</guid>
      <dc:creator>JackZ295</dc:creator>
      <dc:date>2019-07-18T22:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Outputting a Data Set Using Proc Freq That Gives Frequency of Responses for Categorical Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574833#M12748</link>
      <description>&lt;P&gt;Sure, here's one way. To get the values displayed with what you want, I suggest creating a format, see the second set of code that illustrates how to do that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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=sample;
table A1Q1 A2Q1 RFQ1 SE1Q1 SE2Q1 SE3Q1 SE4Q1 I1Q1 I2Q1 I3Q1;
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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's how to create and apply formats:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/proc_format_example.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/proc_format_example.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This does it for age ranges, but you can do single values as well. That should get you started.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/213376"&gt;@JackZ295&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there a way to find the frequency of all of the responses of several categorical variables and output this data in a new data set? The possible responses of each categorical variable are as follows:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1: No, strongly disagree&lt;/P&gt;
&lt;P&gt;2: No, somewhat disagree&lt;/P&gt;
&lt;P&gt;3: Neither agree nor disagree&lt;/P&gt;
&lt;P&gt;4: Yes, somewhat agree&lt;/P&gt;
&lt;P&gt;5: Yes, strongly agree&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a sample data set that I would want to run a proc freq on:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; sample&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;id&lt;/SPAN&gt; A1Q1 A2Q1 RFQ1 SE1Q1 SE2Q1 SE3Q1 SE4Q1 I1Q1 I2Q1 I3Q1&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;1 2 1 1 3 3 4 2 5 3 2 
2 1 1 1 1 1 1 1 1 1 1
3 2 3 4 5 1 2 3 4 5 1 
4 1 2 3 4 5 5 4 3 2 1
5 1 1 1 1 1 1 1 1 1 1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After I do so, I would want to output the frequency of responses for each of these categorical variables in a new data set. Is there a way to do so? How would I do so for the following variables: A1Q1 A2Q1 RFQ1 SE1Q1 SE2Q1 SE3Q1 SE4Q1 I1Q1 I2Q1 I3QQ1 I4Q1 all in one new data set?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 00:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574833#M12748</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-19T00:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Outputting a Data Set Using Proc Freq That Gives Frequency of Responses for Categorical Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574835#M12749</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, thanks for your help. Is there an easier way to do it? This seems rather complicated and not all of the variables show up.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 00:43:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574835#M12749</guid>
      <dc:creator>JackZ295</dc:creator>
      <dc:date>2019-07-19T00:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Outputting a Data Set Using Proc Freq That Gives Frequency of Responses for Categorical Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574836#M12750</link>
      <description>&lt;P&gt;There are other approaches.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Transpose to a long format via PROC TRANSPOSE or a data step&lt;/P&gt;
&lt;P&gt;2. PROC FREQ for summary statistics same as above&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data is all there, it's just not show, the display is limited to 20 observations because of the (obs=20) data set option on the PROC PRINT statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/213376"&gt;@JackZ295&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, thanks for your help. Is there an easier way to do it? This seems rather complicated and not all of the variables show up.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 00:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574836#M12750</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-19T00:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Outputting a Data Set Using Proc Freq That Gives Frequency of Responses for Categorical Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574843#M12751</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;, thanks for your help. However, can't proc freq only output summary statistics for one variable at a time?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 01:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574843#M12751</guid>
      <dc:creator>JackZ295</dc:creator>
      <dc:date>2019-07-19T01:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Outputting a Data Set Using Proc Freq That Gives Frequency of Responses for Categorical Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574847#M12752</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/213376"&gt;@JackZ295&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;, thanks for your help. However, can't proc freq only output summary statistics for one variable at a time?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you ran my first solution you should look at the intermediate table after the proc freq that has all the values into a single table, from multiple variables. But that doesn't matter with the transpose approach because you then run a two way table and the outputs all go to a single table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data would look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Question Value
Q1 1
Q1 3
Q3 5
Q2 2
Q4 5
Q8 2
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then run a PROC FREQ between the question and value to get the desired table in a cleaner format. Think it's the same amount of steps overall. You'll still need to add your PROC FORMAT.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 01:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574847#M12752</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-19T01:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Outputting a Data Set Using Proc Freq That Gives Frequency of Responses for Categorical Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574864#M12753</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp; thanks so much for your help. However, is there a source where I can read up more on how to create formats? I somewhat understand the output, but I don't really understand the code used to create it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is the code "ods table" interchangeable with the code "ods output"? Is that just to create an ODS Output dataset?&amp;nbsp; Is onewayfreqs the name of the table while temp is the name of the data set in which the table is created?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am especially confused about these two lines of code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variable=scan(table, 2);&lt;BR /&gt;Variable_Value=strip(trim(vvaluex(variable)));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your help.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 04:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/574864#M12753</guid>
      <dc:creator>JackZ295</dc:creator>
      <dc:date>2019-07-19T04:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Outputting a Data Set Using Proc Freq That Gives Frequency of Responses for Categorical Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/575079#M12791</link>
      <description>Variable is getting the variable name, look at the original output table, likely called temp, and see what the table variable originally contains. &lt;BR /&gt;&lt;BR /&gt;The Variable_Value - well, SAS outputs each variable to it's own variable output. So this takes the variable name and finds the column with that name and obtains the value. &lt;BR /&gt;&lt;BR /&gt;For Formats find the paper called "Not just another pretty face" that covers formats pretty well. &lt;BR /&gt;&lt;BR /&gt;For PROC FREQ - check the documentation and examples. &lt;BR /&gt;&lt;BR /&gt;For ODS OUTPUT see Rick Wicklins blog post, capturing any output.</description>
      <pubDate>Sat, 20 Jul 2019 00:04:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Outputting-a-Data-Set-Using-Proc-Freq-That-Gives-Frequency-of/m-p/575079#M12791</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-20T00:04:40Z</dc:date>
    </item>
  </channel>
</rss>

