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
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;
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.
What are the rules (in spoken language) for
- calculating amt
- setting flag
?
@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?
We are not saying it as wrong just flagging it up to say it might be a mistake
@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?
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?
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?
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
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.