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

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!

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.

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