DATA Step, Macro, Functions and more

flagging up duplicates with incorrect decimal places

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

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

 


Accepted Solutions
Solution
‎08-24-2016 11:12 PM
Contributor
Posts: 39

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;

View solution in original post


All Replies
Super User
Posts: 5,081

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
Posts: 6,935

Re: flagging up duplicates with incorrect decimal places

What are the rules (in spoken language) for

- calculating amt

- setting flag

?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 31

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
Posts: 17,797

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?

Contributor
Posts: 31

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
Posts: 17,797

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
Posts: 10,490

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
Posts: 10,490

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?

Contributor
Posts: 31

Re: flagging up duplicates with incorrect decimal places

Lets say my data set looks like this 

amt1amt2
1006000.1
80800000.01
600060
60600
601000
1414500
-10-1000000
1500115.001
15.00115001

 

 

I would like that to be flagged as 

 

amt1amt2Flag
1006000.1.
80800000.011
6000601
606001
601000.
1414500.
-10-10000001
1500115.0011
15.001150011

 

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
Contributor
Posts: 39

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;
Contributor
Posts: 31

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 Smiley Happy rather than doing it in 3 steps.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 430 views
  • 8 likes
  • 6 in conversation