BookmarkSubscribeRSS Feed
llt34c
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;
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

6 REPLIES 6
ballardw
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;
run;
llt34c
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.

Astounding
PROC Star

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.

llt34c
Calcite | Level 5

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

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

Astounding
PROC Star

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?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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