turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Building an If statement

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-20-2013 11:54 AM

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

%CHANGE: IIf([TOTAL PAID]<>[FIRST PAYMENT AMOUNT],([TOTAL PAID]/[FIRST

PAYMENT AMOUNT])-1)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to brywhi11

11-20-2013 12:10 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to brywhi11

11-20-2013 12:10 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to brywhi11

11-20-2013 01:13 PM

Thank you both!