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;
The Boston Area SAS Users Group (BASUG) is hosting an in person Meeting & Training on June 27!
Full details and registration info at https://www.basug.org/events.

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;
The Boston Area SAS Users Group (BASUG) is hosting an in person Meeting & Training on June 27!
Full details and registration info at https://www.basug.org/events.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 973 views
  • 0 likes
  • 3 in conversation