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

Hi i am trying to weight the pourcentage and the N in a proc tabulate procedure. I try multiple approch but none of them seems to work. 

 

Here is my syntax ((I need reapet the proc tabulate procedure over 200 times (for 200 differents variables)) all with the same weight variables. 

 

proc tabulate data=SWS1819;
class SH_LOS01 &SH_GROUP / missing;
table (SH_LOS01 ALL = 'total'),  (&SH_GROUP)*  (n='#' colpctn='%'); 
run;

 

Thanks if you can help me. 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@philippe777 wrote:

Here is an example.

 

I just try FREQ, it look like my N change but not like I want. 

 

So I want the N to be weight because I know the real population number and when I weight with proc freq for exemple the N represents all the population not just the sample. 

 

For example in the excel file (want but weight) I know that the total N when it is weight, it should be 54 036 (real population number). Unweight it is 38982. 

 

thanks for your help.


Since you haven't shown any INPUT data or what you expect the output to look like we are guessing as to your need.

 

I seems like you might want to add a dummy variable with the value of 1 to each record, add that variable as a VAR record, apply the weight value and use SUM and PCTSUM on the dummy variable.

 

Maybe something like:

data swstab;
   set sws1819;
   dummy=1;
run;

proc tabulate data=SWStab;
   weight weightvar;
   class SH_LOS01 &SH_GROUP / missing;
   var dummy;
table (SH_LOS01 ALL = 'total'),  (&SH_GROUP)* dummy=''*(sum='#' colpctsum='%'); 
run;

For readability if the &sh_group has many variables it might be better to use that in the row dimension instead of the column dimension.

 

 

 

View solution in original post

4 REPLIES 4
ballardw
Super User

A small example data set and what you expect for output.

 

If your "weight" is a count variable then use FREQ instead of Weight.

 

Consider that the N statistic is intended to be a count what would the actual meaning of a non-integer weighted N be?

 

 

 

 

philippe777
Calcite | Level 5

Here is an example.

 

I just try FREQ, it look like my N change but not like I want. 

 

So I want the N to be weight because I know the real population number and when I weight with proc freq for exemple the N represents all the population not just the sample. 

 

For example in the excel file (want but weight) I know that the total N when it is weight, it should be 54 036 (real population number). Unweight it is 38982. 

 

thanks for your help.

ballardw
Super User

@philippe777 wrote:

Here is an example.

 

I just try FREQ, it look like my N change but not like I want. 

 

So I want the N to be weight because I know the real population number and when I weight with proc freq for exemple the N represents all the population not just the sample. 

 

For example in the excel file (want but weight) I know that the total N when it is weight, it should be 54 036 (real population number). Unweight it is 38982. 

 

thanks for your help.


Since you haven't shown any INPUT data or what you expect the output to look like we are guessing as to your need.

 

I seems like you might want to add a dummy variable with the value of 1 to each record, add that variable as a VAR record, apply the weight value and use SUM and PCTSUM on the dummy variable.

 

Maybe something like:

data swstab;
   set sws1819;
   dummy=1;
run;

proc tabulate data=SWStab;
   weight weightvar;
   class SH_LOS01 &SH_GROUP / missing;
   var dummy;
table (SH_LOS01 ALL = 'total'),  (&SH_GROUP)* dummy=''*(sum='#' colpctsum='%'); 
run;

For readability if the &sh_group has many variables it might be better to use that in the row dimension instead of the column dimension.

 

 

 

philippe777
Calcite | Level 5

Work perfectly thanks a lot.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 820 views
  • 0 likes
  • 2 in conversation