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. 

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!

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
  • 6 replies
  • 1014 views
  • 1 like
  • 4 in conversation