Help using Base SAS procedures

Building an If statement

Occasional Contributor
Posts: 5

Building an If statement

I'm still new to SAS and I'm not sure if it can be done but though I would
ask. I'm trying to build an IFF statement similar to what you can do in Access.

I have two columns (total paid and first payment). If total paid = first payment
then I don't what to return anything. If total paid is > the first payment I
want to divide the total paid by first payment i.e.

Here is what I used in access


Super User
Posts: 6,751

Re: Building an If statement

It's easier than you would think.  Something like this:

if total_paid ne first_payment then percent_change = (total_paid / first_payment) - 1;

Automatically, this statement does nothing when total_paid equals first_payment.

The harder part of the question is understanding your data.  Do you really have only two columns, and not a third column identifying who is making the payment?  Do you really have a column that repeats the first payment value for every row belonging to that person?  If the answer is yes, then adding the statement above should be all you need.

Good luck.

Super User
Super User
Posts: 8,069

Re: Building an If statement

Depends on where you want to "return" this value.

Normally for this type of calculation you would want to create a new variable.

Assuming you have variables named TOTAL_PAID and FIRST_PAYMENT_AMOUNT and want to create variable NEW.

if total_paid = first_payment_amount then new = .;

else new = (total_paid/first_payment_amount) -1 ;

Note that you should not use <> to mean NOT EQUAL in SAS as that is the symbol for the MAX operator.

Occasional Contributor
Posts: 5

Re: Building an If statement

Thank you both!

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation