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
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;
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
Your log would have the error right before FROM.
Remove the comma before the keyword FROM.
@Reeza once again caught it, my example was meant to not be the last part of the select list.
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!
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.