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
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;
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;
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
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.