SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rishabhns
Calcite | Level 5

Hi all,

 

I need help putting in currency symbols in the salary column to the data set below:

 

data new;
input empcode salary country $;
cards;
1001 1473.33 USA
1002 1560.00 UK
1003 1646.67 india
1004 1733.33 japan
1005 1820.00 netherlands
1006 1906.67 poland
1007 1933.33 zimbabwe;
run;

 

I was told that this could be done using PROC FORMAT. The values should still be numeric, they just need the correct currency symbols. Any help is greatly appreciated

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Please explain more what you want.  If you want display the SALARY variable using the US currency symbol of a $ then you could use the DOLLAR format. No need for PROC FORMAT.

If you want to display a different symbol based on the value of COUNTRY then one format will not help since a format attached to a variable applies to every observation.  You will probably need to make a new variable that has the text.

If you want to convert the COUNTRY name into a symbol then PROC FORMAT could help.

proc format ;
  value $currency 'USA'='$' 'UK'='£' 'netherlands'='€';
run;  

You could then use that when making your new character variable.

data want;
  set new;
  length salary_display $20 ;
  salary_display=cats(put(country,$currency.),put(salary,comma12.2));
run;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Please explain more what you want.  If you want display the SALARY variable using the US currency symbol of a $ then you could use the DOLLAR format. No need for PROC FORMAT.

If you want to display a different symbol based on the value of COUNTRY then one format will not help since a format attached to a variable applies to every observation.  You will probably need to make a new variable that has the text.

If you want to convert the COUNTRY name into a symbol then PROC FORMAT could help.

proc format ;
  value $currency 'USA'='$' 'UK'='£' 'netherlands'='€';
run;  

You could then use that when making your new character variable.

data want;
  set new;
  length salary_display $20 ;
  salary_display=cats(put(country,$currency.),put(salary,comma12.2));
run;
andreas_lds
Jade | Level 19
What do expect as result? You can only assign one format to a variable, so displaying different currency symbols depending on the of the county-variable while maintaining numeric type is hardly possible.
rishabhns
Calcite | Level 5

The end result should look like the following

empcode    salary    Country
1001           $1473.33    USA

1002           £1560.00    UK

1003           ₹1646.67    India

 

and the rest of the symbols for their corresponding countries and currencies

 

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1756 views
  • 1 like
  • 3 in conversation