turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Difference in percentage

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2014 02:54 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2014 06:26 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2014 03:21 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2014 03:29 AM

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 |

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2014 03:37 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2014 06:26 AM

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;