BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rahul88888
Obsidian | Level 7

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
JohnHoughton
Quartz | Level 8

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

11 REPLIES 11
Astounding
PROC Star

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.

rahul88888
Obsidian | Level 7
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
Reeza
Super User

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

rahul88888
Obsidian | Level 7

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

 

Reeza
Super User

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

ballardw
Super User

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?

ballardw
Super User

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?

rahul88888
Obsidian | Level 7

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 

JohnHoughton
Quartz | Level 8

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;
rahul88888
Obsidian | Level 7
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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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