BookmarkSubscribeRSS Feed
mdbenson
Calcite | Level 5

Hi,

I'm very new to SAS and I've written this code and it bombs out.  Could any of you experts show me there errors of my way?  I'm trying to get the average, max and count (some quarters are missing) for 4 quarters of data.  Also, in the WHERE statement at the bottom, I'm trying to subset where the Recipients were the 3 listed??  Can I use the ||  to mean OR?  I thought I read you could.  Any help would be great!

proc sql;

  select Employee_ID 'Employee ID',

  (sum(Qtr1, Qtr2, Qtr3, Qtr4)/count(Qtr1, Qtr2, Qtr3, Qtr4)) as avg_don 'Average Donation',

  max(Qtr1, Qtr2, Qtr3, Qtr4) as max_don 'Maximum Donation',

  count(Qtr1, Qtr2, Qtr3, Qtr4) as qtr_don 'Quarters Donated'

  from sqldata.employee_donations

  where (find(Recipients, "Bob" || "Kevin" || "Ashely", "i") > 0);

quit;

4 REPLIES 4
LinusH
Tourmaline | Level 20

What dos your source data look like, and what is the desired result?

As for the OR operator, a single pipe is used in SAS. || means character concatenation of the two expressions surrounding it.

SAS(R) 9.4 Language Reference: Concepts, Second Edition

Be sure that you don't confuse SQL aggregation functions (works over columns) and the corresponding SAS functions (works on a row level).

Data never sleeps
mdbenson
Calcite | Level 5

The original data has Employee ID, quarterly donations made (Qtr1, Qtr2, Qtr3, Qtr4), and Recipients of the donations (I just changed those to peoples name to be more generic.  They can be the name of any 3 charities).  I want to find the avg donation, max donation, and the count (that is, how many quarters did each Employee donate).  Thanks for the info on the OR that I was trying to perform.  That was meant to act as a filter to just find data on certain charities.

Thanks!

Patrick_Tan
Fluorite | Level 6

Asuming you want to calculate the statistics per employee I am missing the "group by Employee_ID" statement.

mdbenson
Calcite | Level 5

Thanks Patrick_Tan.  I'll add that.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1732 views
  • 0 likes
  • 3 in conversation