BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lu_king
Obsidian | Level 7
I have a data set that contains date of sample, site locations, main samples duplicate samples, and PH levels. I am trying to average the non-zero duplicate samples with the main samples, specific to the location (matching SA to SA, and AU to AU). Any advice would be appreciated!

For example,
Date location sample ph level
5/6 SA Main 2.5
5/7 SA Dup 6.467
5/6 AU Main .04
5/7 AU Dup 0
1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Maybe add a WHERE statement to Tom's code, e.g.

proc summary data=have;
  by date location;
  var ph_level;
  output out=want mean=mean_ph_level;
  where ph_level ne 0;
run;

or 

proc summary data=have;
  by date location;
  var ph_level;
  output out=want mean=mean_ph_level;
  where NOT (location='Dup' and ph_level=0) ;
run;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Should be simple.

proc summary data=have;
  by date location;
  var ph_level;
   output out=want mean=mean_ph_level;
run;

I don't understand this part "the non-zero duplicate samples with the main samples".  0 should be a perfectly valid value of pH.  Why would you want to exclude them?

 

lu_king
Obsidian | Level 7
Hi Tom, thanks for your help! I didn’t want the zero averaging with the main sample because most of the time a zero is due to a user error/malfunction (the sampler is clogged, someone forgot to run it, etc). Usually a note is made but sometimes it isn’t, I figure if the duplicate yielded a zero then there was no need to average it with the main sample.
Quentin
Super User

Maybe add a WHERE statement to Tom's code, e.g.

proc summary data=have;
  by date location;
  var ph_level;
  output out=want mean=mean_ph_level;
  where ph_level ne 0;
run;

or 

proc summary data=have;
  by date location;
  var ph_level;
  output out=want mean=mean_ph_level;
  where NOT (location='Dup' and ph_level=0) ;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1113 views
  • 0 likes
  • 3 in conversation