- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi experts,
I have two datasets say, first and second. They can generate any values every month. The values of same column needs to be add and substract in first dataset (as shown in Result below). The result (a_out and b_out) needs to be compared with value from second dataset (c_out).
Compare c_out with a_out
Also compare c_out with b_out
Display 'matching' or 'not matching'.
The validation needs to be sent to the users.
data first;
input a b;
datalines;
22 25
44 0
33 14
22 0
;
run;
Result:
a_out = (22 + 44) - (33 + 22)
b_out = ( 25 + 0) - (14 + 0)
I have c_out from other table.
data second;
input c_out;
datalines;
11
;
run;
The same calculation needed for several LOBs and I want to write macro for the same. Please reply with the above solution at least. Thank you in advance.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's a way to get the FINAL data set. But leaving a message for the user is far too broad a task to attempt without more clarification on the form of the message. I leave that part to you.
data second;
input c_out;
datalines;
11
;
data final;
input a b;
retain factor 1;
if _n_=3 then factor = -1;
a_out + factor * a;
b_out + factor * b;
if _n_=4;
set second;
keep a_out b_out c_out;
datalines;
22 25
44 0
33 14
22 0
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@bk8 wrote:
Hi experts,
I have two datasets say, first and second. They can generate any values every month. The values of same column needs to be add and substract in first dataset (as shown in Result below). The result (a_out and b_out) needs to be compared with value from second dataset (c_out).
Compare c_out with a_out
Also compare c_out with b_outDisplay 'matching' or 'not matching'.
The validation needs to be sent to the users.
data first;
input a b;
datalines;
22 25
44 0
33 14
22 0
;
run;Result:
a_out = (22 + 44) - (33 + 22)
b_out = ( 25 + 0) - (14 + 0)I have c_out from other table.
data second;
input c_out;
datalines;
11
;
run;
The same calculation needed for several LOBs and I want to write macro for the same. Please reply with the above solution at least. Thank you in advance.
Is data first always exactly four rows of data? If not, you need to provide a rule based on the contents of the data set that will allow us to determine which rows get added and which subtracted.
You should really provide what the output should look like after the compare. I can interpret that a number of ways.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For the above example, I need new dataset to be created, say 'final' and the output should look like
a_out b_out c_out
11 11 11
And the message should be like,
'c_out is matching with a_out and b_out'.
If the results are different then we can give error message as for e.g., 'c_out is matching with b_out but is off by $3 with a_out' (its just sample).
Please let me know if it is not clear yet. Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's a way to get the FINAL data set. But leaving a message for the user is far too broad a task to attempt without more clarification on the form of the message. I leave that part to you.
data second;
input c_out;
datalines;
11
;
data final;
input a b;
retain factor 1;
if _n_=3 then factor = -1;
a_out + factor * a;
b_out + factor * b;
if _n_=4;
set second;
keep a_out b_out c_out;
datalines;
22 25
44 0
33 14
22 0
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content