Sorry to bother you again. I have two follow up questions:
1. How to add weight variable to the code? I guess the code always print out the unweighted result of n and rowpctn. I tried to add a weight variable but getting same as unweighted result.
2. How to modify the table to meet certain conditions? for example, if my result (with rowpctns) looks like below:
a b c d
a
b 10/40 16/40 4/40 10/40
c
d
For the row of "b", the cell corresponding to col "c" has count of 4 and rwopctn=4/(10+16+4+10). But for data confidentiality reason, I cannot include that number if my result. The condition is that the cell count cannot be less than 5. I have to recalculate the result (for row "b") as
a b c d
b 10/(10+16+10) 16/(10+16+10) -- 10/(10+16+10)
So the row "b", the rowpctn will be based on the total number by delete the count from col "c".
I am not sure if my question is clear of not. Please let me know if it is not clear to you.
Thanks.
Try WEIGHT statement.
data test;
input x1 $ x2 $;
cards;
a a
a a
a b
a c
a d
b b
b a
b c
b d
c c
c c
c c
c a
d d
d a
d b
d b
;
run;
proc sql;
create table temp as
select x1,x2,count(*) as m,case when count(*) <=2 /*<--Change it into 5*/ then .
else count(*) end as weight
from test
group by x1,x2;
quit;
proc tabulate data=temp;
class x1 x2;
var m;
table x1='',x2=''*m=''*(sum='n' rowpctsum='rowpctsum%')/misstext='0';
weight weight;
run;
Thank you very much!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.