BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
IgorR
Quartz | Level 8

Hi,

I'm trying to make the following code to be shorter:

	If Period = 40 Then Do;
			If Years > 20 and Years < 30 Then
				Effect_on_Guarantee = 1;
			Else Effect_on_Guarantee = Lapse_Multipliers;
		End;
	Else Effect_on_Guarantee = Lapse_Multipliers;

To achieve this I'm trying to use IFN function like this:

IFN(a.Period = 40, IFN((a.Period  > 20 and a.Period < 30),1, Lapse_Multipliers),Lapse_Multipliers) As Effect_on_Guarantee

In This way IFN doesn't return any error or warning but doesn't the work as along version of code does.

Where is a mistake?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@IgorR wrote:

In This way IFN doesn't return any error or warning but doesn't the work as along version of code does.

Where is a mistake?


You have NOT told us what is wrong. Saying it doesn't work gives us no useful information. What do you see that is wrong?

 

Why do you switch from a variable named YEAR to a variable named PERIOD? Could that be the problem?

--
Paige Miller

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Why would you want to convert readable code into a function call?

If it is so you add it to an SQL statement then use CASE clause.

case when (Period = 40) then
  case when (Years > 20 and Years < 30) then 1 else Lapse_Multipliers end
  else Lapse_Multipliers
end

If you want to reduce the LOGIC of the test then do:

case when ((Period = 40) and (Years > 20 and Years < 30)) then 1 
  else Lapse_Multipliers
end

 

PaigeMiller
Diamond | Level 26

@IgorR wrote:

In This way IFN doesn't return any error or warning but doesn't the work as along version of code does.

Where is a mistake?


You have NOT told us what is wrong. Saying it doesn't work gives us no useful information. What do you see that is wrong?

 

Why do you switch from a variable named YEAR to a variable named PERIOD? Could that be the problem?

--
Paige Miller
IgorR
Quartz | Level 8
Oh, Thank you!
What a silly mistake.
The problem indeed in switching Years to Period.
Now I fixed it and it works.

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 802 views
  • 2 likes
  • 3 in conversation