BookmarkSubscribeRSS Feed
PNC
Fluorite | Level 6 PNC
Fluorite | Level 6

I have a table of data and need to use one calculation for one region and a different calculation for the other regions.  The calculations would include other columns of data.  Is it possible to combine functions into one calculated column.

 

Data includes Region and Current Balance. 

 

This is what I am trying to accomplish:

 

If the Region = X and the Current Balance is <100,000 then the end result is a flat $200. For Region X, if the Current Balance is >100,000 the end result is Current Balance*.0025. For all other Regions if the Current Balance is <100,000 then the end result is a flat $500 or if the Current Balance is >100,000 then the end result is Current Balance*.005.

 

How do I accomplish this? I am not a programmer and need to be able to do this within the Query Builder.  Thank you.

3 REPLIES 3
tomrvincent
Rhodochrosite | Level 12

You'd have to do it using the advanced expression option.  It kind of walks you thru it a bit, in that the functions are all listed as well as their parameters.

ChrisHemedinger
Community Manager

In your case, you'd want the CASE statement in your Advanced expression.  Something like:

 

case
 when region="X" and balance<100000 then 200
 when region="X" and balance>=100000 then balance*.0025
 when region ^="X" and balance<100000 then 500
 else balance*.005
end /* as NewValue */ 

The expression builder will add the "as NewValue" bit on for you, but you'll have to pretty much enter the rest.  You can try the Recode Values option instead -- it might give you some point and click methods for this.  The end result would still be a CASE clause.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
PNC
Fluorite | Level 6 PNC
Fluorite | Level 6

Thank you!  I haven't had a chance to see if this will work yet, but I believe it will do what I need.  I appreciate the help.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1147 views
  • 0 likes
  • 3 in conversation