data dsn;
input empcode salary country $;
datalines;
1001 $1,473.33 US
1002 £1,560.00 UK
1003 ₹1,646.67 India
1004 ¥1,733.33 Japan
1005 ƒ1,820.00 Netherlands
1006 ₽1,906.67 Poland
1007 Z$1,993.33 Zimbabwe
;
run;
i am unable to read the data
How do you want this data to appear? Do you want $1,473.33 and £1,560.00 to represent the numbers 1473.33 and 1560 or?
hi draycut;
good afternoon
i want output as it is with decimals also
$1,473.33
£1,560.00
@BrahmanandaRao wrote:
hi draycut;
good afternoon
i want output as it is with decimals also
$1,473.33
£1,560.00
I don't think that you can get that output as number, because only one format can be assigned to a variable and there is no format containing different currency-symbols.
data dsn;
input empcode salary country $;
datalines;
1001 $1,473.33 US
1002 £1,560.00 UK
1003 ₹1,646.67 India
1004 ¥1,733.33 Japan
1005 ƒ1,820.00 Netherlands
1006 ₽1,906.67 Poland
1007 Z$1,993.33 Zimbabwe
;
run;
Just get rid of your currency symbols and read it using the COMMAw. informat:
data dsn ;
input empcode salary :comma. country :$20. ;
cards ;
1001 1,473.33 US
1002 1,560.00 UK
1003 1,646.67 India
1004 1,733.33 Japan
1005 1,820.00 Netherlands
1006 1,906.67 Poland
1007 1,993.33 Zimbabwe
run ;
Kind regards
Paul D.
Read as character, use compress() to only keep digits, and then input() with a 10.2 (or longer if required) informat.
@Kurt_Bremser wrote:
Read as character, use compress() to only keep digits, and then input() with a 10.2 (or longer if required) informat.
I would keep the period also and use an informat that does not imply a specific number of decimal places.
Note also that you can just use the maximum width of 32 for the informat instead of trying to guess how long the largest value might be.
@Kurt_Bremser wrote:Read as character, use compress() to only keep digits, and then input() with a 10.2 (or longer if required) informat.
HI
KurtBremser,
if we read as character it may be problem when use numeric functions like max salary
then what we have to do?
You read into a temporary character variable, and after compressing use input() to create the final numeric variable. Drop the temporary variable.
Code example:
data dsn;
input empcode _salary :$20. country $;
salary = input(compress(_salary,'.','kd'),20.);
length currency $3;
currency = compress(_salary,',.','d');
format salary comma20.2;
drop _salary;
datalines;
I added a variable to keep the currency symbols/names.
Why do you re-post your question? The old thread is https://communities.sas.com/t5/SAS-Programming/Currency-reading/m-p/580743
You cannot store the amount and the currency type into the same variable.
Store them in two separate variables.
data dsn;
length empcode $10 raw_salary $20 currency $8 salary 8 country $20 ;
input empcode raw_salary country &;
currency=compress(raw_salary,' ,.0123456789');
salary=input(compress(raw_salary,currency),comma32.);
format salary comma14.2;
datalines4;
1001 $1,473.33 US
1002 £1,560.00 UK
1003 ₹1,646.67 India
1004 ¥1,733.33 Japan
1005 ƒ1,820.00 Netherlands
1006 ₽1,906.67 Poland
1007 Z$1,993.33 Zimbabwe
;;;;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.