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 our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
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 our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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