<?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 combine seven columns for one set of freq in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-seven-columns-for-one-set-of-freq/m-p/616039#M180280</link>
    <description>&lt;P&gt;This is one way - you can run the code directly and it will create a clean table with all in the same format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*This code is an example of how to generate a table with 
Variable Name, Variable Value, Frequency, Percent, Cumulative Freq and Cum Pct
No macro's are required
Use Proc Freq to generate the list, list variables in a table statement if only specific variables are desired
Use ODS Table to capture the output and then format the output into a printable table.
*/

*Run frequency for tables;
ods table onewayfreqs=temp;
proc freq data=sashelp.class;
	table sex age;
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;However, I suspect you actually want something different, so I'd recommend you transpose your data set such that you have a data set where its&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID Question Response&lt;/P&gt;
&lt;P&gt;1 90_10&amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;1 90_20&amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;1 90_30&amp;nbsp; &amp;nbsp;3&lt;/P&gt;
&lt;P&gt;2 90_10&amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can accomplish this via a transpose procedure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some transposing data tutorials:&lt;BR /&gt;&lt;BR /&gt;Wide to Long:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Once the data set is flipped you can then use the following code instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
table question * response;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I analyze a lot of survey data and find this data structure much more useful than your original data structure.&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/294494"&gt;@c-skissner&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;Below are&amp;nbsp;my tables I have individual freq sets.&amp;nbsp; I would like to combine all the tables into one set of freqs for a combine total.&amp;nbsp; I am not familiar enough with programming or the SAS program, but I am learning.&amp;nbsp; What programming is needed to complete&amp;nbsp;my issue?&amp;nbsp; Thank you Steve&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;freq&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=WORK.'Combined MCOs'n;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_10 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_20 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_30 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_40 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_50 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_60 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_70 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jan 2020 20:23:22 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-01-08T20:23:22Z</dc:date>
    <item>
      <title>how to combine seven columns for one set of freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-seven-columns-for-one-set-of-freq/m-p/616032#M180278</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Below are&amp;nbsp;my tables I have individual freq sets.&amp;nbsp; I would like to combine all the tables into one set of freqs for a combine total.&amp;nbsp; I am not familiar enough with programming or the SAS program, but I am learning.&amp;nbsp; What programming is needed to complete&amp;nbsp;my issue?&amp;nbsp; Thank you Steve&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;freq&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=WORK.'Combined MCOs'n;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;tables&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;'q_90_10 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;tables&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;'q_90_20 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;tables&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;'q_90_30 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;tables&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;'q_90_40 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;tables&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;'q_90_50 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;tables&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;'q_90_60 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;tables&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;'q_90_70 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 20:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-seven-columns-for-one-set-of-freq/m-p/616032#M180278</guid>
      <dc:creator>c-skissner</dc:creator>
      <dc:date>2020-01-08T20:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine seven columns for one set of freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-seven-columns-for-one-set-of-freq/m-p/616039#M180280</link>
      <description>&lt;P&gt;This is one way - you can run the code directly and it will create a clean table with all in the same format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*This code is an example of how to generate a table with 
Variable Name, Variable Value, Frequency, Percent, Cumulative Freq and Cum Pct
No macro's are required
Use Proc Freq to generate the list, list variables in a table statement if only specific variables are desired
Use ODS Table to capture the output and then format the output into a printable table.
*/

*Run frequency for tables;
ods table onewayfreqs=temp;
proc freq data=sashelp.class;
	table sex age;
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;However, I suspect you actually want something different, so I'd recommend you transpose your data set such that you have a data set where its&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID Question Response&lt;/P&gt;
&lt;P&gt;1 90_10&amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;1 90_20&amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;1 90_30&amp;nbsp; &amp;nbsp;3&lt;/P&gt;
&lt;P&gt;2 90_10&amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can accomplish this via a transpose procedure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some transposing data tutorials:&lt;BR /&gt;&lt;BR /&gt;Wide to Long:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Once the data set is flipped you can then use the following code instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
table question * response;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I analyze a lot of survey data and find this data structure much more useful than your original data structure.&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/294494"&gt;@c-skissner&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;Below are&amp;nbsp;my tables I have individual freq sets.&amp;nbsp; I would like to combine all the tables into one set of freqs for a combine total.&amp;nbsp; I am not familiar enough with programming or the SAS program, but I am learning.&amp;nbsp; What programming is needed to complete&amp;nbsp;my issue?&amp;nbsp; Thank you Steve&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;freq&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=WORK.'Combined MCOs'n;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_10 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_20 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_30 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_40 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_50 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_60 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;tables&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;'q_90_70 - No1 - Yes'n&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 20:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-seven-columns-for-one-set-of-freq/m-p/616039#M180280</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-08T20:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine seven columns for one set of freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-seven-columns-for-one-set-of-freq/m-p/616896#M180693</link>
      <description>&lt;P&gt;Thank you for your assistance.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 13:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-seven-columns-for-one-set-of-freq/m-p/616896#M180693</guid>
      <dc:creator>c-skissner</dc:creator>
      <dc:date>2020-01-13T13:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine seven columns for one set of freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-seven-columns-for-one-set-of-freq/m-p/616990#M180727</link>
      <description>Your welcome but please mark the correct answer as the solution, not your post.</description>
      <pubDate>Mon, 13 Jan 2020 17:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-seven-columns-for-one-set-of-freq/m-p/616990#M180727</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-13T17:54:33Z</dc:date>
    </item>
  </channel>
</rss>

