Obsidian | Level 7

## flagging up duplicates with incorrect decimal places

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

1 ACCEPTED SOLUTION

Accepted Solutions
Quartz | Level 8

## Re: flagging up duplicates with incorrect decimal places

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;``
11 REPLIES 11
PROC Star

## Re: flagging up duplicates with incorrect decimal places

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.

Super User

## Re: flagging up duplicates with incorrect decimal places

What are the rules (in spoken language) for

- calculating amt

- setting flag

?

Obsidian | Level 7

## Re: flagging up duplicates with incorrect decimal places

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
Super User

## Re: flagging up duplicates with incorrect decimal places

@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?

Obsidian | Level 7

## Re: flagging up duplicates with incorrect decimal places

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

Super User

## Re: flagging up duplicates with incorrect decimal places

@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?

Super User

## Re: flagging up duplicates with incorrect decimal places

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?

Super User

## Re: flagging up duplicates with incorrect decimal places

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?

Obsidian | Level 7

## Re: flagging up duplicates with incorrect decimal places

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

Quartz | Level 8

## Re: flagging up duplicates with incorrect decimal places

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;``
Obsidian | Level 7

## Re: flagging up duplicates with incorrect decimal places

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.
Discussion stats
• 11 replies
• 1530 views
• 8 likes
• 6 in conversation