BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nikhiljain22740
Fluorite | Level 6
Hi,

I've a csv data file that have a salary column. Salary is stored from globally so having dollar, euro, pond... etc symbol. Need help to read such type data into sas.

Example :
Salary
$30,000
€25,000
€40,000
¥80,000
...

Please help me to read this data in sas.

Thanks
Nikhil Jain
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@Nikhiljain22740

You can split the source string into the currency symbol and the amount as done in the code below.

You will need lookup tables for anything else like conversion to 3 letter currency codes or conversion of currency amounts to a baseline currency.

data have;
  infile datalines truncover;
  input amount_string $20.;
  currency_amt=input(compress(amount_string,'.','kd'),best32.);
  currency_symbol=substrn(amount_string,1,anydigit(amount_string)-1);
  datalines;
$30,000
€25,000
€40,000
¥80,000
;
run;

 

View solution in original post

5 REPLIES 5
Patrick
Opal | Level 21

@Nikhiljain22740

You can split the source string into the currency symbol and the amount as done in the code below.

You will need lookup tables for anything else like conversion to 3 letter currency codes or conversion of currency amounts to a baseline currency.

data have;
  infile datalines truncover;
  input amount_string $20.;
  currency_amt=input(compress(amount_string,'.','kd'),best32.);
  currency_symbol=substrn(amount_string,1,anydigit(amount_string)-1);
  datalines;
$30,000
€25,000
€40,000
¥80,000
;
run;

 

Ksharp
Super User

Patrick,

You gonna know €25,000 is expressed as  25.000 not 25000

Patrick
Opal | Level 21

@Ksharp

I've interpreted the comma as thousand separator so the value should become 25000

In case the comma is the decimal separator then the function reading the amount would need to look like:

  currency_amt=input(compress(amount_string,',','kd'),commax32.);

 

....and I would need to see a string with actual decimals to come up with the final function suitable for the string pattern at hand. 

 

In my country of origin the value would be written: 25'000,00 

Nikhiljain22740
Fluorite | Level 6
Thanks Patrick, It'll work but is there any generic solution like any format that we can apply on it.
Patrick
Opal | Level 21

@Nikhiljain22740

As far as I know there isn't any SAS provided format to convert currency symbols into currency codes. It shouldn't be that hard though to create one.

As for currency conversion: There can't be a pre-fabricated format. You'll need a currency conversion table where you lookup conversion rates with some date_key, currency_key type approach.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 5 replies
  • 1165 views
  • 0 likes
  • 3 in conversation