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

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 

SendXYCState
Y1.100AL
Y2.28AL
Y..56AL
...55AL
...77AL
...30AL
Y102544PA
Y203289PA
Y304378PA
.402743PA
..1022PA
...34PA

 

Output should be something like 

 State = AL   
 Send=YSend=.Send=YSend=.Total Records
 CountCountPercentagePercentage 
X2433.3366.666
Y00006
C3350506

 

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

 

Can anyone please help ?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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 

 

Can anyone please help ?


 

View solution in original post

6 REPLIES 6
Reeza
Super User

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 

 

Can anyone please help ?


 

ballardw
Super User

@Reeza 

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).

Reeza
Super User
Ah, thanks BallardW.
jhh197
Pyrite | Level 9
Thank you for all your help !
jhh197
Pyrite | Level 9
Thank you . Report or Dataset anything should be fine
jhh197
Pyrite | Level 9

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 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 6 replies
  • 1793 views
  • 4 likes
  • 3 in conversation