BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Konkordanz
Pyrite | Level 9

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
/*
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;

View solution in original post

5 REPLIES 5
Konkordanz
Pyrite | Level 9

Thx for answering!

And right, I corrected it in the initial post. But it doesn't change the problem I described.

Ksharp
Super User
/*
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;
Konkordanz
Pyrite | Level 9

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?

Ksharp
Super User
table (age ="" all),weight*(mean n); /*with bracket*/

Will take into account of missing value of both AGE and WEIGHT since bracket belong to WEIGHT.



table (age ="" all),weight*mean n; /*without bracket*/

Only consider about AGE is missing or not sine n is not in bracket.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 241 views
  • 0 likes
  • 3 in conversation