BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
c-skissner
Fluorite | Level 6

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
c-skissner
Fluorite | Level 6

Thank you for your assistance.

View solution in original post

3 REPLIES 3
Reeza
Super User

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;


 

c-skissner
Fluorite | Level 6

Thank you for your assistance.

Reeza
Super User
Your welcome but please mark the correct answer as the solution, not your post.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 630 views
  • 0 likes
  • 2 in conversation