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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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