Pyrite | Level 9

## Calculate percentages for each variable in a Dataset

I have a Dataset TEST which has below variables Send, X, Y, C State . Need to calculate how many values are populated and what percentage of values populated for each variable  when Send = Y and Sender =. by State

TEST

 Send X Y C State Y 1 . 100 AL Y 2 . 28 AL Y . . 56 AL . . . 55 AL . . . 77 AL . . . 30 AL Y 10 25 44 PA Y 20 32 89 PA Y 30 43 78 PA . 40 27 43 PA . . 10 22 PA . . . 34 PA

Output should be something like

 State = AL Send=Y Send=. Send=Y Send=. Total Records Count Count Percentage Percentage X 2 4 33.33 66.66 6 Y 0 0 0 0 6 C 3 3 50 50 6

Similarly for PA calculate the count of records populated and percentage of records populated when Send = Y and send =. for each variable by State

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Calculate percentages for each variable in a Dataset

PROC TABULATE is your best bet for a displayed report and PROC MEANS for a data set. Do you need a data set or a report?

``````proc tabulate data=have;
by state;
class send x y c / missing;
table x y c, Send*(N) / printmiss misstext='0';
run;``````

This does not do the percentages though you can do that. See the documentation for examples for the percentages.

https://documentation.sas.com/?docsetId=proc&docsetTarget=p0vdza4puzkcghn1j5xtqfb4sahr.htm&docsetVer...

@jhh197 wrote:

I have a Dataset TEST which has below variables Send, X, Y, C State . Need to calculate how many values are populated and what percentage of values populated for each variable  when Send = Y and Sender =. by State

TEST

 Send X Y C State Y 1 . 100 AL Y 2 . 28 AL Y . . 56 AL . . . 55 AL . . . 77 AL . . . 30 AL Y 10 25 44 PA Y 20 32 89 PA Y 30 43 78 PA . 40 27 43 PA . . 10 22 PA . . . 34 PA

Output should be something like

 State = AL Send=Y Send=. Send=Y Send=. Total Records Count Count Percentage Percentage X 2 4 33.33 66.66 6 Y 0 0 0 0 6 C 3 3 50 50 6

Similarly for PA calculate the count of records populated and percentage of records populated when Send = Y and send =. for each variable by State

6 REPLIES 6
Super User

## Re: Calculate percentages for each variable in a Dataset

PROC TABULATE is your best bet for a displayed report and PROC MEANS for a data set. Do you need a data set or a report?

``````proc tabulate data=have;
by state;
class send x y c / missing;
table x y c, Send*(N) / printmiss misstext='0';
run;``````

This does not do the percentages though you can do that. See the documentation for examples for the percentages.

https://documentation.sas.com/?docsetId=proc&docsetTarget=p0vdza4puzkcghn1j5xtqfb4sahr.htm&docsetVer...

@jhh197 wrote:

I have a Dataset TEST which has below variables Send, X, Y, C State . Need to calculate how many values are populated and what percentage of values populated for each variable  when Send = Y and Sender =. by State

TEST

 Send X Y C State Y 1 . 100 AL Y 2 . 28 AL Y . . 56 AL . . . 55 AL . . . 77 AL . . . 30 AL Y 10 25 44 PA Y 20 32 89 PA Y 30 43 78 PA . 40 27 43 PA . . 10 22 PA . . . 34 PA

Output should be something like

 State = AL Send=Y Send=. Send=Y Send=. Total Records Count Count Percentage Percentage X 2 4 33.33 66.66 6 Y 0 0 0 0 6 C 3 3 50 50 6

Similarly for PA calculate the count of records populated and percentage of records populated when Send = Y and send =. for each variable by State

Super User

## Re: Calculate percentages for each variable in a Dataset

We can't use X Y or C as CLASS variables in Proc Tabulate, at least with the data values shown, as we get too many rows.

My headache with this is that @jhh197 wants to count a value of Send=Y in the Send=. cells. He is not counting missing Send but missing X in that case (the third row of data).

Super User

## Re: Calculate percentages for each variable in a Dataset

Ah, thanks BallardW.
Pyrite | Level 9

## Re: Calculate percentages for each variable in a Dataset

Thank you for all your help !
Pyrite | Level 9

## Re: Calculate percentages for each variable in a Dataset

Thank you . Report or Dataset anything should be fine
Pyrite | Level 9

## Re: Calculate percentages for each variable in a Dataset

Thank you for all your help . When i ran the code below is the output . Here can i get the count of X , Y,C and percentage of X, Y,C  instead of listing distinct values of X, Y,C  when Send = Y and Send = . by State

State=AL
Send
Y
N  N
X

.       3 1
1      0 1
2      0 1
Y

.        3 3

1         0  1
2         0 1
3         0 1
4         1 0
5         1 0
6         1 0
Thank you so much for all help

Discussion stats
• 6 replies
• 1574 views
• 4 likes
• 3 in conversation