BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to calculate for each varaible (from a list of varaibles):

(1)-number of observations in each category

(2)-number of observations in each category that fail(fail is ind=1)

(3)-PCT of failure calculated by (1)/(2)

Required output: (with empty row gap with black  background  between varaibles)

Required_output.PNG

 

Data ttt;
input ID x $ w $ y $ z $ q $ r $ t $ ind;
cards;
1 x1 w2 y2 z3 q1 0
2 x2 w2 y1 z1 q1 1
3 x1 w1 y1 z2 q2 0
4 x3 w3 y1 z2 q2 0
5 x1 w2 y1 z2 q1 0
6 x1 w1 y2 z1 q2 1
7 x2 w3 y2 z1 q1 0
;
run;
 

 

2 REPLIES 2
ballardw
Super User

First thing: your Input statement tries to read 9 variables. You only provide values for 7.

 

Second, fill in some example values in the result. The datamay need to be reshaped to make a table of that form because to have a separate column for "VAR" and "Category" requires additional variables. And how the reshape goes will be affected by what the ID variable does.

 

This may get you close:

Proc tabulate data=ttt;
   class x w y z q;
   var ind;
   table x w y z q,
         ind *(n='nr obs' sum='nr fail obs'*f=best5. mean='pct fail'*f=percent8.1)
         /nocellmerge
   ;
run;

But tabulate needs another variable(s) to make the first column and the options to create and color a blank line adding even more data to have something to indicate the colors for the cell, borders and such based on value and using formats to indicate what color.

 

 

Ksharp
Super User
Data ttt;
input ID x $ w $ y $ z $ q $ ind;
cards;
1 x1 w2 y2 z3 q1 0
2 x2 w2 y1 z1 q1 1
3 x1 w1 y1 z2 q2 0
4 x3 w3 y1 z2 q2 0
5 x1 w2 y1 z2 q1 0
6 x1 w1 y2 z1 q2 1
7 x2 w3 y2 z1 q1 0
;
run;
proc transpose data=ttt out=temp;
by id ind;
var x w y z q ;
run;

proc report data=temp nowd;
column _name_ col1 n ind=ind_sum ind=ind_mean;
define _name_/group 'var' order=data;
define col1/group 'category';
define n/'Nr_Obs';
define ind_sum/analysis sum 'Nr_Fail_Obs';
define ind_mean/analysis mean 'PCT_Fail' format=percent8.2;
compute before _name_/style={background=verylightgray};
_n+1;len=10;
if _n=1 then len=0;
dummy=' ';
line dummy $varying10. len;
endcomp;
run;

Doing homework ?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1037 views
  • 3 likes
  • 3 in conversation