Hi!
I have to compare if 2 fields from 2 different tables are the same or at least, see how much the difference is.
I have var "price1" from table1 and var "price2" from table2. Both tables in the same library.
How can I print the comparision between price1 and price2 in one only output like this:
price1 | price2 | difference |
5 | 5 | 0 |
thank you!
@clipsia wrote:
sorry but Im talking about huge tables.
I just need sum(price1) because is the total sum of the variable that Im comparing
Then you summarize the data with a procedure like Proc Means or summary, then combine.
Proc summary data=have; var price1; output out=work.price1sum sum=; run;
will create a data set with the sum or Price1 (and couple of other variables you can ignore for the moment).
Do the same with the other data set. Then combine.
Combine the data into one data set then do the comparison.
If there is a variable or combination of variables to match the two on that makes more sense.
data one; input id price1; datalines; 1 4 2 5 3 77 ; data two; input id price5; datalines; 1 1 2 15 3 12 ; data want; merge one two; by id; difference = price1 - price5; run; proc print data=want; var price1 price5 difference; run;
If you only have one record then the merge still works. If there are multiple records and you want to match them on a variable(or more) then sort by the matching variable prior to the data step with the merge.
There are other ways possible as well. Example data of more complex problems would be needed for any solution.
sorry but Im talking about huge tables.
I just need sum(price1) because is the total sum of the variable that Im comparing
@clipsia wrote:
sorry but Im talking about huge tables.
I just need sum(price1) because is the total sum of the variable that Im comparing
Then you summarize the data with a procedure like Proc Means or summary, then combine.
Proc summary data=have; var price1; output out=work.price1sum sum=; run;
will create a data set with the sum or Price1 (and couple of other variables you can ignore for the moment).
Do the same with the other data set. Then combine.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.