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

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.

Ksharp
Super User

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 17 replies
  • 2235 views
  • 6 likes
  • 4 in conversation