DATA Step, Macro, Functions and more

Convert amount present in different Currencies to one currency using Proc Format.!!

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Convert amount present in different Currencies to one currency using Proc Format.!!

Hi All,

 

SAS Newbee.. I have a file having separate fields for amount and currency e.g.

Amount1 Amount2 Currency

 

There are 3 fixed currencies used inhere i.e. (INR-base, SGD, USD). No other currency type will ever be used. and they have the fixed value for exchange rate.

 

Currently I was usign the approach, created an exchange rate file (with fields Currency and EXRATE) and then using the currency as key field, multiplied the amount in file1 as per the exchange rate recieved.

 

I just wanted to know, if there's some other way round for this. Can we use PROC FORMAT or anyother way to make this happen in PROC SQL i.e. whenever I encounter SGD, multiply the amount field by exrate.

 

Thanks.


Accepted Solutions
Solution
‎02-23-2016 03:50 AM
Super User
Posts: 6,963

Re: Convert amount present in different Currencies to one currency using Proc Format.!!

[ Edited ]

A quick shot, using a format:

proc format library=work;
invalue exch
  'INR' = 1.5
  'SGD' = 2.5
  'USD' = 0.8
;
run;

data have;
input curr $ amount;
cards;
INR 100
SGD 200
USD 50
;
run;

data want;
set have;
internal = amount * input(curr,exch.);
run;

One might also consider using a hash object to store the exchange rates, but to me the format method is simpler.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎02-23-2016 03:50 AM
Super User
Posts: 6,963

Re: Convert amount present in different Currencies to one currency using Proc Format.!!

[ Edited ]

A quick shot, using a format:

proc format library=work;
invalue exch
  'INR' = 1.5
  'SGD' = 2.5
  'USD' = 0.8
;
run;

data have;
input curr $ amount;
cards;
INR 100
SGD 200
USD 50
;
run;

data want;
set have;
internal = amount * input(curr,exch.);
run;

One might also consider using a hash object to store the exchange rates, but to me the format method is simpler.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 8

Re: Convert amount present in different Currencies to one currency using Proc Format.!!

perfect. Thanks. Smiley Happy
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 234 views
  • 0 likes
  • 2 in conversation