BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sas_R
Calcite | Level 5

Hello ,

I'm trying to get the percentage of 1=Yes values for each question (Q1,Q2 etc)  within each ID variable.  Below is my data sample and desired output.

I did this using PROC SQL with sub queries but I'd like to get the same results using one of SAS procedure, I don't know maybe proc tabulate or proc freq etc... Could you please help ?

Data

IDQ1Q2Q3Q4
A1111
A1010
A0010
A1100
B1100
B0101
B0010

Output

IDQ1_PQ2_PQ3_PQ4_P
A0.750.50.750.25
B0.33330.6666670.33330.3333
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

I don't know if it needs transpose or not.  Maybe you just want percent.

proc summary data=q nway;
  
class ID;
   output out=percent mean(q:)=;
   run;

View solution in original post

4 REPLIES 4
data_null__
Jade | Level 19

I would go ahead as get N, count, and percent.

data q;
   input ID:$1. Q1-Q4;
   cards;
A 1 1 1 1
A 1 0 1 0
A 0 0 1 0
A 1 1 0 0
B 1 1 0 0
B 0 1 0 1
B 0 0 1 0
;;;;
   run;
ods select none;
proc means n sum mean stackods;
   class id;
   ods output summary=summary(rename=(sum=count mean=percent));
   run;
ods select all;
proc print;
  
format _all_;
   run;
Sas_R
Calcite | Level 5

Thank you, it seems like your process also needs transpose procedure for the output. I'll work on that.

data_null__
Jade | Level 19

I don't know if it needs transpose or not.  Maybe you just want percent.

proc summary data=q nway;
  
class ID;
   output out=percent mean(q:)=;
   run;
Sas_R
Calcite | Level 5

Thank you so much, I learned another procedure today...way better than Proc sql....

Best Regards...

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 914 views
  • 1 like
  • 2 in conversation