BookmarkSubscribeRSS Feed
Ujjawal
Quartz | Level 8

Hi Everyone,

I have a datafile containing survey responses with demographics. Let's say, 10 questions (Q1-Q10) and 3 demographics ( Age, Gender and Experience). All questions are six-point scale questions. That means 6 choices in multiple choice questions.

I want to calculate count percentage of 5 and 6 for each questions by Age demographic. Age demog contains 5 options. I used Proc Freq statement but it doesn't allow me to break question frequency by Age. And i didn't find any option for count percentage in Proc MEANS or Proc SUMMARY.

Is it possible to accomplish this using Proc SUMMARY?? I don't want to use PROC SQL for this as i am learning SAS Base Smiley Wink

Thanks in advance !

4 REPLIES 4
Ksharp
Super User

where is your sample data and the final output you need ?

Do you mind to use proc tabulate or proc report ?

Ksharp

Ksharp
Super User
data have;
input age q1 q2;
cards;
12 1 2
12 6 5
12 5 6
12 2 6
22 6 2
22 2 5
22 5 6
22 5 6
;
run;
data temp(drop=i q:);
 set have;
 array x{*} q: ;
 do i=1 to dim(x);
  name=vname(x{i});value=x{i};output;
 end;
run;
proc sort data=temp;
 by age name value;
run;
proc freq noprint;
table age*name*value/list out=want(where=(value in (5 6))) nocum;
run;

Ksharp

Ujjawal
Quartz | Level 8

Hi KSharp,

Thank you very much for writing the code.

It is generating count percentage of 5 or 6 separately. I am looking for the combined percentage of 5 and 6.

Thanks once again !

Ksharp
Super User

use proc format.

data have;
input age q1 q2;
cards;
12 1 2
12 6 5
12 5 6
12 2 6
22 6 2
22 2 5
22 5 6
22 5 6
;
run;
data temp(drop=i q:);
 set have;
 array x{*} q: ;
 do i=1 to dim(x);
  name=vname(x{i});value=x{i};output;
 end;
run;
proc sort data=temp;
 by age name value;
run;





proc format;
value fmt
  5,6='5 and 6';
run;

proc freq noprint;
table age*name*value/list out=want(where=(value in (5 6))) nocum;
format value fmt.;
run;




Ksharp

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2120 views
  • 2 likes
  • 2 in conversation