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
- /
- Base SAS Programming
- /
- flagging up duplicates with incorrect decimal plac...

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
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-24-2016 01:54 AM

I have a data like this

data x;

input amt1 amt2;

datalines;

100.00 6000.10

60.00 60000.01

6000.00 60.00

60.00 600.00

60.00 1000.00

14.00 14500.00

-10.00 -1000000.00

15001 15.001

15.001 15001

;

run;

I would like to have it flagged as below

amt1 amt2 amt flag

100 6000.1 60 .

60 60000.01 1000 1

6000 60 100 1

60 600 10 1

60 1000 16.66667 .

14 14500 1035.714 .

-10 -1000000 100000 1

15001 15.001 1000.067 1

15.001 15001 1000.067 1

this is the bit of code i have written but is not solving the purpose

data x;

set x;

amt = (int(substr(amt1,1,find(amt1,"."))))/(int(substr(amt2,1,find(amt2,"."))));

if amt =1 or amt = 0.1 or amt=0.01 or amt = 0.001 or amt = 0.0001 then good = 1; else good=0;

run;

Thanks

Accepted Solutions

Solution

08-24-2016
11:12 PM

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

Posted in reply to rahul88888

08-24-2016 02:46 PM

Check if amt1 and amt 2 have the same sign and check if log10(amt1/amt2) is an integer.

`if amt1/amt2>0 and int(log10(amt1/amt2))=log10(amt1/amt2) then flag=1;`

All Replies

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

Posted in reply to rahul88888

08-24-2016 02:21 AM

How is it possible that the last two lines of data both generate the same AMT?

You might have to actually describe the outcome that you would like. Showing nonworking code makes it difficult to determine your objective here.

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

Posted in reply to rahul88888

08-24-2016 02:50 AM

What are the rules (in spoken language) for

- calculating amt

- setting flag

?

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

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

Posted in reply to KurtBremser

08-24-2016 05:41 AM

The flagging reason is incorrect decimal places used

like the real amt is 60.00 however written as 600.00 sho it should be flagged up

like the real amt is 60.00 however written as 600.00 sho it should be flagged up

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

Posted in reply to rahul88888

08-24-2016 05:54 AM

rahul88888 wrote:

The flagging reason is incorrect decimal places used

like the real amt is 60.00 however written as 600.00 sho it should be flagged up

But how do we know what's wrong? That it should be 60 vs 600?

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

Posted in reply to Reeza

08-24-2016 06:42 AM

We are not saying it as wrong just flagging it up to say it might be a mistake

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

Posted in reply to rahul88888

08-24-2016 06:45 AM

rahul88888 wrote:

We are not saying it as wrong just flagging it up to say it might be a mistake

So how do we know it might be a mistake?

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

Posted in reply to rahul88888

08-24-2016 11:17 AM

Here's a hint for providing and talking about example data:

**Do not provide multiple example data values and then reference one of those values without context.**

rahul88888 wrote:

The flagging reason is incorrect decimal places used

like the real amt is 60.00 however written as 600.00 sho it should be flagged up

Your example data has the value 60 repeated 4 times and 6000 3 times. So when you say 60 or 6000 we have no way to tell which other information may be important.

Is there supposed to be some relationship between amt1 and amt2 that you have not mentioned? Or is there some "rule" involving multiple rows of data?

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

Posted in reply to rahul88888

08-24-2016 11:18 AM

Here's a hint for providing and talking about example data:

**Do not provide multiple example data values and then reference one of those values without context.**

rahul88888 wrote:

The flagging reason is incorrect decimal places used

like the real amt is 60.00 however written as 600.00 sho it should be flagged up

Your example data has the value 60 repeated 4 times and 6000 3 times. So when you say 60 or 6000 we have no way to tell which other information may be important.

Is there supposed to be some relationship between amt1 and amt2 that you have not mentioned? Or is there some "rule" involving multiple rows of data?

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

Posted in reply to ballardw

08-24-2016 11:42 AM

Lets say my data set looks like this

amt1 | amt2 |

100 | 6000.1 |

80 | 800000.01 |

6000 | 60 |

60 | 600 |

60 | 1000 |

14 | 14500 |

-10 | -1000000 |

15001 | 15.001 |

15.001 | 15001 |

I would like that to be flagged as

amt1 | amt2 | Flag |

100 | 6000.1 | . |

80 | 800000.01 | 1 |

6000 | 60 | 1 |

60 | 600 | 1 |

60 | 1000 | . |

14 | 14500 | . |

-10 | -1000000 | 1 |

15001 | 15.001 | 1 |

15.001 | 15001 | 1 |

Thats all the problem is decimals have been incorrectly put or something. We just need to flag it

Solution

08-24-2016
11:12 PM

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

Posted in reply to rahul88888

08-24-2016 02:46 PM

Check if amt1 and amt 2 have the same sign and check if log10(amt1/amt2) is an integer.

`if amt1/amt2>0 and int(log10(amt1/amt2))=log10(amt1/amt2) then flag=1;`

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

Posted in reply to JohnHoughton

08-24-2016 11:15 PM

I had multiplied it earlier both abs(amt1) and abs(amt2) with 10^50 and changed the number to string matched the first 48 characters and completed it. The solution you have given is petty awesome rather than doing it in 3 steps.