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
- /
- General Programming
- /
- comparing 2 amount values

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

04-20-2016 05:21 AM

hi ,

iam trying to monitor some financial figures. i have 2 values that i need to work with but i just dont have an idea on how i will write this interms of sas coding. please help

my values are as follows

Trans_Type | Amount |

salary | 10000 |

Cheq dep | 1000 |

Teller dep | 5000 |

my desire results is that any amount that is more than 20% of the salary should be flagged 1. and any amount below 20% of the salary should be flagged 0. anyone please help urgently!!!

thanks in advance

Accepted Solutions

Solution

04-26-2016
02:20 AM

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

04-20-2016 09:15 AM

In that case, it will not work. Even i thought the same. We can do one thing, capture the salary in macro variable and using it in the datastep.

data m1;

input type $ amount;

cards;

sal 10000

cheq 2000

teller 5000

;

proc sql noprint;

select amount into : amt from m1 where type='sal';

quit;

data m2;

set m1;

x=&amt.;

if amount/x > 0.20 then flag=1; else flag=0;

run;

~Manohar

All Replies

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

04-20-2016 05:30 AM

hi ,

iam trying to monitor some financial figures. i have 2 values that i need to work with but i just dont have an idea on how i will write this interms of sas coding. please help

my values are as follows:

Trans_Type Amount

Salary 10000

Cheq Dep 1000

Sandry Dep 2000

my desire results is that any amount that is more than 20% of the salary should be flagged 1. and any amount below 20% of the salary should be flagged 0. anyone please help urgently!!!

thanks in advance

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

04-20-2016 05:59 AM

Please post some more sample data and expected output. You'll need to modify it to match your data structure but it should help you get started.

```
Proc SQL;
Create table want as
Select a.id, a.type, a.amount, case when a.amount/b.amount >= 0.2 then 1 else 0 as flag
From have as a
Left join have as b
On a.id = b.id
And a.type ne 'Salary' and b.type. = 'Salary';
Quit;
```

You our can merge data with itself via SQL and then do calculation.

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

04-20-2016 06:07 AM

Hi Reeza

thanks for the clarity.

i see that your code joins two tables. how will the code be if the data is contained in one table. like in my sample code provided. how can i compare first value of 'Salary' to other values?

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

04-20-2016 06:17 AM

Take a closer look at the code. It joins the table Have to itself, Have.

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

04-20-2016 06:27 AM

Thanks Reeza

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

04-20-2016 05:21 AM

hi ,

iam trying to monitor some financial figures. i have 2 values that i need to work with but i just dont have an idea on how i will write this interms of sas coding.

my values are as follows

Trans_Type | Amount |

salary | 10000 |

Cheq dep | 1000 |

Teller dep | 5000 |

my desire results is that any amount that is more than 20% of the salary should be flagged 1. and any amount below 20% of the salary should be flagged 0. anyone please help urgently!!!

thanks in advance

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

04-20-2016 07:58 AM

data m1;

input type $ amount;

cards;

sal 10000

cheq 2000

teller 5000

;

run;

data m2;

set m1;

if type='sal' then x=amount;

retain x;

if amount/x > 0.20 then flag=1; else flag=0;

run;

proc print;run;

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

04-20-2016 08:07 AM

thanks Manu

you guys are stars i truly appreciate this

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

04-20-2016 08:21 AM

What if Salary isn't in the first record but a later record?

Solution

04-26-2016
02:20 AM

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

04-20-2016 09:15 AM

In that case, it will not work. Even i thought the same. We can do one thing, capture the salary in macro variable and using it in the datastep.

data m1;

input type $ amount;

cards;

sal 10000

cheq 2000

teller 5000

;

proc sql noprint;

select amount into : amt from m1 where type='sal';

quit;

data m2;

set m1;

x=&amt.;

if amount/x > 0.20 then flag=1; else flag=0;

run;

~Manohar