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.
@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.
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?
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.
@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.
Work perfectly thanks a lot.
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 16. Read more here about why you should contribute and what is in it for you!
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.