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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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
;

View solution in original post

4 REPLIES 4
ballardw
Super User

@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_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.


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.

bk8
Calcite | Level 5 bk8
Calcite | Level 5
Yes, the first dataset always has 4 rows and second dataset has 1 row.
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.
Astounding
PROC Star

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
;
bk8
Calcite | Level 5 bk8
Calcite | Level 5
Thank you so much @Astounding. This logic works well and able to tweek my code and got the result.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 694 views
  • 1 like
  • 3 in conversation