BookmarkSubscribeRSS Feed

Hi,

I have the following code but I cant get the logic to work.

The variables names are correct and I think the code I have produce should show what im trying to achieve. If anyone can interpret that I would be grateful. I thin the first 2 are correct and maybe the 4th one but not 100%

case when Date_Term_Prod = Key_hedge then Conversion_Rate_hedge else 0 end as Alco_pc,

Case when Product_Term_comps = Term_hedge_2 then Prepayment_rate_hedge_2 else 0 end as prepayment,

case when alco_pc = 0 then sum(Pipeline_ytd, Pipeline_ytd*alco_pc) end as pipeline_x_alco_pc,

sum(case when pipeline_x_alco_pc + Completions_ytd * prepayment) as LTD,

case when Product_end_date = 0 then sum(Weekly_movement_Allocs * prepayment) else sum(Weekly_movement_Allocs * Alco_pc * prepayment) as weekly_movement

3 REPLIES 3
PGStats
Opal | Level 21

Every expression seems syntactically correct, except the fourth one which contains an incomplete CASE expression.

Are you aware that there are two kinds of SUM functions in your query? SUM(x, y) simply returns x + y, whereas SUM(x*y), ...  GROUP BY a returns the sum of x*y over every value of a. The first one is a SAS datastep function and the second one is a SQL aggregate function.

PG

PG

No I wasn't aware of that, thank you.

Reeza
Super User

There's no way to say what's 'correct' without having sample input/output data. They may syntactically correct, but be logically incorrect.

This appears incorrect to me, you'd at least need an END.

sum(case when pipeline_x_alco_pc + Completions_ytd * prepayment) as LTD,

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3977 views
  • 1 like
  • 3 in conversation