How do I sum up a column of values if it matches an if statement?
fx
if variable = XX and variable2 = YY then sum variable
proc summary data=have(where=(variable=XX and variable2=YY)); var myvariable; output out=sums sum=; run;
In SQL
sum(case when var1 = "XX" and var2 ="YY" then var3 else 0 end)
Data.
Example data is good.
Starting and desired result.
Since "sum" typically involves more than one value where the values currently reside is important.
With your "sum up column" then the order of data and such can become a very critical part of the solution.
So show us some data.
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.