Fluorite | Level 6

how to combine seven columns for one set of freq

Below are my tables I have individual freq sets.  I would like to combine all the tables into one set of freqs for a combine total.  I am not familiar enough with programming or the SAS program, but I am learning.  What programming is needed to complete my issue?  Thank you Steve

proc freq data=WORK.'Combined MCOs'n;

tables 'q_90_10 - No1 - Yes'n;

tables 'q_90_20 - No1 - Yes'n;

tables 'q_90_30 - No1 - Yes'n;

tables 'q_90_40 - No1 - Yes'n;

tables 'q_90_50 - No1 - Yes'n;

tables 'q_90_60 - No1 - Yes'n;

tables 'q_90_70 - No1 - Yes'n;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Fluorite | Level 6

3 REPLIES 3
Super User

Re: how to combine seven columns for one set of freq

This is one way - you can run the code directly and it will create a clean table with all in the same format.

``````/*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;``````

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

ID Question Response

1 90_10   1

1 90_20   1

1 90_30   3

2 90_10   2

....

You can accomplish this via a transpose procedure.

Here are some transposing data tutorials:

Wide to Long:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/

https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/

Once the data set is flipped you can then use the following code instead:

``````proc freq data=have;
table question * response;
run;``````

I analyze a lot of survey data and find this data structure much more useful than your original data structure.

@c-skissner wrote:

Below are my tables I have individual freq sets.  I would like to combine all the tables into one set of freqs for a combine total.  I am not familiar enough with programming or the SAS program, but I am learning.  What programming is needed to complete my issue?  Thank you Steve

proc freq data=WORK.'Combined MCOs'n;

tables 'q_90_10 - No1 - Yes'n;

tables 'q_90_20 - No1 - Yes'n;

tables 'q_90_30 - No1 - Yes'n;

tables 'q_90_40 - No1 - Yes'n;

tables 'q_90_50 - No1 - Yes'n;

tables 'q_90_60 - No1 - Yes'n;

tables 'q_90_70 - No1 - Yes'n;

run;

Fluorite | Level 6