BookmarkSubscribeRSS Feed

Hi I need help in writing a SAS PRC SQL Script please -  

 

I need to say - 

if substr(loan_type,1,1) <> "B" then repayment_strategy_for_IO_PP = 'SP' else repayment_strategy_for_IO_PP = the rest of the data

 

Thanks in advance

6 REPLIES 6
Kurt_Bremser
Super User

 

case when substr(loan_type,1,1) <> "B"
then 'SP'
else x.repayment_strategy_for_IO_PP
end as repayment_strategy_for_IO_PP,

where x is the alias for the contributing dataset, set in the "from" part.

 

 

I have written my code like this, but getting errors so i'm assuming I haven't written it out as you would expect? 

 

proc sql;
create table work.score_2 as
select
*,
case when substr(loan_type,1,1) <> "B"
then 'SP'
else repayment_strategy_for_IO_PP
end as repayment_strategy_for_IO_PP,
from work.score_1;
quit;

Astounding
PROC Star

I believe that <> has different meaning in SQL vs. a DATA step.  What are you picturing that <> should mean?

I need to make sure that if -

1. Property = residential

2. Repayment Method = Interest only and Part repayment

3. Then repayment strategy = Sale of Mortgage Property

else bring back everything else. 

 

So the variables are - 

Loan_Type = 'R'

Type_of_loan IN 'R','P'

repayment_strategy_for_IO_PP = 'SP'

 

But I need to make sure that if the criteria isn't hit above, that the rest of the case present as normal if that makes sense

Reeza
Super User

Your log would have the error right before FROM. 

 

Remove the  comma before the keyword FROM. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1753 views
  • 1 like
  • 4 in conversation