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.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 5 replies
  • 421 views
  • 0 likes
  • 3 in conversation