Help using Base SAS procedures

Proc Mean Statement

Reply
Occasional Contributor
Posts: 13

Proc Mean Statement

[ Edited ]

I have a data set I am trying to get averages (of two difference variables) for by day. I have been succesfful in the past with the below code but after adding some more variables and merging more data, I am not getting averages for every day. It does it for some but not for all. It appears that on days when I am missing values for that variable, and thus the mean should be ".", it is leaving them separate. What can i do?  Below is my code. 

 

proc sort data=sows;by a b c d e;
Run;
proc means Noprint data=example;
by a b c d e;
Var x y;
Output Out=Totals
MEAN (x y) = xavrg yavrg;
Run;
Proc print data=Totals;
run;
data example; set Totals (keep=a b c d e xavrg yavrg);
Proc Print data=example;
run;

 

 

Thanks

Super User
Posts: 11,343

Re: Proc Mean Statement

Are you expecting to get a missing result because some but not all of an analysis variable is missing for some values of your date variable?

 

I am not sure what you may mean by "leaving them separate". It would help to have a small input data set (in the form of a data step please) and the output that shows what you mean.

 

 

And does this generate output that might be what your are looking for in the final print:

proc tabulate data=example;
   class a b c d e;
   var x y;
   tables a*b*c*d*e,
          (x y)*mean;
run;
Occasional Contributor
Posts: 13

Re: Proc Mean Statement

The proc tabulate did not work because the data set is too large. Leaving them separate as in, it is not taking an average and is providing me with more than one value for that day. This is happening when the x variable has missing values.

 

My data set is imported in. There are 37 variables and 157696 observations. I am missing observations for many variables and a period is in those cells.

 

I have attached some data.

 

Thanks for your help.

Super User
Posts: 5,513

Re: Proc Mean Statement

Are you trying to say that DAY is one of the five variables that you called A B C D E?

 

If DAY is missing, how is SAS supposed to know what DAY it should be?  You will have to fix that first, if you want the values to appear in order by DAY.

Occasional Contributor
Posts: 13

Re: Proc Mean Statement

Posted in reply to Astounding

Day is not missing for any observations. For a and b variables, there are no missing values.

Super User
Posts: 11,343

Re: Proc Mean Statement

[ Edited ]

Which is your day variable?

 

What generated the "output"?

And please describe, by variable and row what is wrong.

 

The file size had nothing to do with tabulate not working. Missing values for class variables is another story.

 

What role do the other variables besides the "day" variable play? If you want a summary by day then any other By or Class variable that has more than one value for a given day will generate a level of output. So do the summary by the day variable only.

Super User
Posts: 5,513

Re: Proc Mean Statement

It sounds like we have narrowed this down a little bit.  DAY is either A or B, but we can't tell which one.  Maybe you could tell us.

 

It would also help if you would show a small piece of the PROC PRINT output that illustrates the problem.

 

Maybe both of your analysis variables are always missing on some days.  Is that a possibility?

Ask a Question
Discussion stats
  • 6 replies
  • 445 views
  • 0 likes
  • 3 in conversation