BookmarkSubscribeRSS Feed
JibJam221
Obsidian | Level 7

Hi everyone,

I'm having some troubles regarding a procedure using Proc Freq.

 

I am creating tables based on survey questions that are organized by sex, and would like to combine some of the rows that have similar responses to create more general row labels.

 

For example:

Question 1: rate your level of satisfaction with your current living arrangement

A) Extremely Dissatisfied

B) Dissatisfied

C) Neutral

D) Satisfied

E) Somewhat Satisfied

 

I would like a table that combines responses from A and B to create one row being "dissatisfied", and do the same for responses D and E.

 

I have created my code using proc freq:

 

proc freq data = work.living;

table '1-Rate your Satisfaction with y'n*'What is your gender?'n / nocum nocol norow;

run;

 

all data is organize by gender of the respondent.

any help is appreciated!

 

Thanks!

6 REPLIES 6
mkeintz
PROC Star

You don't have to change values in your data to create 3 groups from 5.  Instead you can define a FORMAT that collapses values, and tell proc freq to honor that format, as in:

 

proc format;
  value $myfmt 'A','B' = 'AB: disatisfied'
               'D','E' = 'DE: satisfied' ;
run;
proc freq data=have;
  tables ques1 ques2;
  format ques1 ques2 $myfmt.;
run;

I've assumed the actual values in ques1 and ques2 are 'A','B','C','D'; and 'E'.  If not change the value statement.

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
JibJam221
Obsidian | Level 7
for the last format statement (under the proc freq), my tables are multi-way (for example):
proc freq data = work.living;
table '1-Rate your Satisfaction with y'n*'What is your gender?'n / nocum nocol norow;'

how would I use the format function under "proc freq" using the table above?

Im receiving errors when trying to do so.
PaigeMiller
Diamond | Level 26

Show us the log so we can see the errors (and the code you used as well). When providing the log, it is critical that you maintain the formatting of the log so we can see it exactly as SAS showed it to you, making it easier for us to use. To maintain the formatting of the log, click on the </> icon and paste the log as text into the window that appears. DO NOT SKIP THIS STEP.

--
Paige Miller
ChrisNZ
Tourmaline | Level 20

Create a format that combines the values into the same group, and apply the format to the variable in the proc freq.

JibJam221
Obsidian | Level 7
Thanks @ChrisNZ - do you think you could provide an example? I tried doing so and it doesn't seem to be working...
thanks!
PaigeMiller
Diamond | Level 26

An example was already provided by @mkeintz 

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1194 views
  • 0 likes
  • 4 in conversation