Hi,
i generate my results with proc-tabulate and a included weight-variable. Afterwards I compare my result with a friends result (made with another software) and I recognize a marginal difference. I researched a lot to find the reason for the difference and I found it: There is one person in my dataset that has no value in the weight-variable. Actually this person should not be part of the result, but it is. So I researched, how to avoid it and found the information:
"Prior to Version 7 of SAS, the procedure did not exclude the observations with missing weights from the count of observations."
http://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1hdr41psnyg4en137jaap5ia951.htm
But my SAS-Version is 9.04.01M7P080520 (proc setinit; run;). So: What is the reason for it? I mean...sure, alternative I always could exclude this person with the where-command. But this isnt a intuitive and smart option. That would be error-prone because I would always have to think of exactly this case.
correct result:
proc tabulate data=mz2020_j;
class wirtschaftsbereich ;
weight HRF_P_Sn;
classlev wirtschaftsbereich / style=[cellwidth=11cm];
var arbeitszeit_tats;
table (wirtschaftsbereich ="" all), arbeitszeit_tats*mean n;
format wirtschaftsbereich Sektor.
where HRF_P_Sn is not null;
run;
wrong result:
proc tabulate data=mz2020_j;
class wirtschaftsbereich ;
weight HRF_P_Sn;
classlev wirtschaftsbereich / style=[cellwidth=11cm];
var arbeitszeit_tats;
table (wirtschaftsbereich ="" all), arbeitszeit_tats*mean n;
format wirtschaftsbereich Sektor.;
run;
/*
Your code is not right ,
if you want take into account of missing value with
analysis variable,you need take 'n' be with it via ().
Check the following:
*/
data have;
set sashelp.class;
w=1;
if _n_=10 then w=.;
run;
proc tabulate data=have;
class age ;
weight w;
classlev age / style=[cellwidth=11cm];
var weight;
table (age ="" all), weight*mean n;
where w is not null;
run;
proc tabulate data=have;
class age ;
weight w;
classlev age / style=[cellwidth=11cm];
var weight;
table (age ="" all),weight*(mean n); /*<--- Check this ,need 'n' within () */
run;
Why do you include the WEIGHT variable in the VAR statement?
Thx for answering!
And right, I corrected it in the initial post. But it doesn't change the problem I described.
/*
Your code is not right ,
if you want take into account of missing value with
analysis variable,you need take 'n' be with it via ().
Check the following:
*/
data have;
set sashelp.class;
w=1;
if _n_=10 then w=.;
run;
proc tabulate data=have;
class age ;
weight w;
classlev age / style=[cellwidth=11cm];
var weight;
table (age ="" all), weight*mean n;
where w is not null;
run;
proc tabulate data=have;
class age ;
weight w;
classlev age / style=[cellwidth=11cm];
var weight;
table (age ="" all),weight*(mean n); /*<--- Check this ,need 'n' within () */
run;
Wow, only the missing bracket was the reason.Thank you!
But what is actually the difference between these two codes?
proc tabulate data=have;
class age ;
weight w;
classlev age / style=[cellwidth=11cm];
var weight;
table (age ="" all),weight*(mean n); /*with bracket*/
run;
proc tabulate data=have; class age ; weight w; classlev age / style=[cellwidth=11cm]; var weight; table (age ="" all),weight*mean n; /*without bracket*/ run;
With the bracketing, the n refers only to "weight" and without brackets the n refers to all involved variables? That means...without parentheses, all cases that have a value in any specified variable are involved?
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!
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.