BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lu_king
Fluorite | Level 6
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;
BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: 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
Fluorite | Level 6
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;
BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 348 views
  • 0 likes
  • 3 in conversation