DATA Step, Macro, Functions and more

IF STATEMENT

Reply
anonymous_user
Posts: 0

IF STATEMENT

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

Super User
Posts: 7,778

Re: IF STATEMENT

Posted in reply to anonymous_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.

 

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
anonymous_user
Posts: 0

Re: IF STATEMENT

Posted in reply to KurtBremser

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;

Super User
Posts: 5,503

Re: IF STATEMENT

Posted in reply to anonymous_user

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

anonymous_user
Posts: 0

Re: IF STATEMENT

Posted in reply to Astounding

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

Super User
Posts: 19,789

Re: IF STATEMENT

Posted in reply to anonymous_user

Your log would have the error right before FROM. 

 

Remove the  comma before the keyword FROM. 

Super User
Posts: 7,778

Re: IF STATEMENT

@Reeza once again caught it, my example was meant to not be the last part of the select list.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 6 replies
  • 258 views
  • 1 like
  • 4 in conversation