BookmarkSubscribeRSS Feed
Calcite | Level 5

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;
proc means Noprint data=example;
by a b c d e;
Var x y;
Output Out=Totals
MEAN (x y) = xavrg yavrg;
Proc print data=Totals;
data example; set Totals (keep=a b c d e xavrg yavrg);
Proc Print data=example;




Super User

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;
Calcite | Level 5

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.

Opal | Level 21

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.

Calcite | Level 5

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

Super User

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.

Opal | Level 21

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?



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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 3 in conversation