BookmarkSubscribeRSS Feed
mmea
Quartz | Level 8

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

3 REPLIES 3
PaigeMiller
Diamond | Level 26
proc summary data=have(where=(variable=XX and variable2=YY));
var myvariable;
output out=sums sum=;
run;
--
Paige Miller
ballardw
Super User

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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 1284 views
  • 3 likes
  • 4 in conversation