Solved
Contributor
Posts: 41

# Difference in percentage

Hi,

I need to compare 2 columns(A with B) values and find out the difference in % in next column I used Dif function but giving only count difference is any other function to identify difference in percentage.

 A B C(Difference in %) 50 20 40 100 30 70 150 135 10

I used below code

data one;

input A B;

cards;

50 20

100 30

150 135

;

run;

data Diff;

Set one;

c = (A- B);

run;

Accepted Solutions
Solution
‎08-04-2014 06:26 AM
Posts: 1,270

## Re: Difference in percentage

Hi,

If you are trying to display values in % then try this.

data one;
input A B;
cards;
50 20
100 30
150 135
;

run;

data Diff;
Set one;
c = (A-B)/A;
format c percent6.1;
run;

All Replies
Posts: 3,215

## Re: Difference in percentage

When you want to work with percentages there must be reference value. With unclear definitions you will not get answers.   Answer=42  .  (the answer for the ultimtate question).

Percentages are often used with misleading expectations. Suppose you are profits are 100% (on original price) then the correction back new to old is 50% lose.

For the first row the absolute difference is 30 reference for 50  is 60%  for 20 that is 150% for an original 100 that is 30% for 70 (the sum) it is 43% for 35 (the mean) 85% . What answer do you like?

---->-- ja karman --<-----
Contributor
Posts: 41

## Re: Difference in percentage

Hi thanks for replay  I need like below out put difference in %.

 A B C(Difference in %) 100 20 80 100 30 70 100 60 40
Posts: 3,215

## Re: Difference in percentage

then your reference is the A column ( ..   / A *100)...   Did you notice your values are already there?

---->-- ja karman --<-----
Solution
‎08-04-2014 06:26 AM
Posts: 1,270

## Re: Difference in percentage

Hi,

If you are trying to display values in % then try this.

data one;
input A B;
cards;
50 20
100 30
150 135
;

run;

data Diff;
Set one;
c = (A-B)/A;
format c percent6.1;
run;

🔒 This topic is solved and locked.