BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathish_jammy
Lapis Lazuli | Level 10

Dear Experts,

 

I have a Questionnaire type dataset to evaluate the value of the boolean type (Y/N) questions.

I shared the sample dataset below for better understanding.

data aaa;
input ID Emp$ Gen$ Q1$ Q2$ Q3$ Q4$ Q5$;
cards;
132 Govt M Y N N N N
321 Prvt F N Y Y N N
159 Prvt F Y Y N N N
357 Govt M N N N N Y
;

I have to calculate the N(sum) and % of how many Y (Yes) checked.

I expect the result as

 

tab.jpg

I tried with Proc Tabulate but it returns partial output.

proc tabulate data = aaa;
class Q1 Q2 Q3 Q4 Q5 Emp Gen;
tables (Q1 Q2 Q3 Q4 Q5)* all, Emp*(Gen);
run;

Please suggest a solution to solve the given problem.

Thanks in advance! 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data aaa;
input ID Emp$ Gen$ Q1$ Q2$ Q3$ Q4$ Q5$;
cards;
132 Govt M Y N N N N
321 Prvt F N Y Y N N
159 Prvt F Y Y N N N
357 Govt M N N N N Y
;
proc transpose data=aaa out=have(where=(col1='Y'));
by id emp gen notsorted;
var Q:;
run;

proc format ;
value $ fmt(notsorted)
 'M'='M'
 'F'='F';
run;
proc tabulate data = have;
class _name_ Emp Gen / preloadfmt order=data;
format gen $fmt.;
tables _name_=' ' all, Emp=' '*Gen=' '*(n colpctn='%')*f=8.0 /printmiss;
run;

View solution in original post

3 REPLIES 3
Ksharp
Super User
data aaa;
input ID Emp$ Gen$ Q1$ Q2$ Q3$ Q4$ Q5$;
cards;
132 Govt M Y N N N N
321 Prvt F N Y Y N N
159 Prvt F Y Y N N N
357 Govt M N N N N Y
;
proc transpose data=aaa out=have(where=(col1='Y'));
by id emp gen notsorted;
var Q:;
run;
proc tabulate data = have;
class _name_ Emp Gen;
tables _name_=' ' all, Emp=' '*Gen=' '*(n colpctn='%')*f=8.0;
run;
Ksharp
Super User
data aaa;
input ID Emp$ Gen$ Q1$ Q2$ Q3$ Q4$ Q5$;
cards;
132 Govt M Y N N N N
321 Prvt F N Y Y N N
159 Prvt F Y Y N N N
357 Govt M N N N N Y
;
proc transpose data=aaa out=have(where=(col1='Y'));
by id emp gen notsorted;
var Q:;
run;

proc format ;
value $ fmt(notsorted)
 'M'='M'
 'F'='F';
run;
proc tabulate data = have;
class _name_ Emp Gen / preloadfmt order=data;
format gen $fmt.;
tables _name_=' ' all, Emp=' '*Gen=' '*(n colpctn='%')*f=8.0 /printmiss;
run;
Sathish_jammy
Lapis Lazuli | Level 10

Thank you so much @Ksharp . Both solutions fit my expected result.

Once again Thanks for your time and consideration.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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