BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
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 

12 REPLIES 12
PeterClemmensen
Tourmaline | Level 20

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?

BrahmanandaRao
Lapis Lazuli | Level 10

hi draycut;

good afternoon

i want output as it is with decimals also

 

 $1,473.33

 £1,560.00

 

 

andreas_lds
Jade | Level 19

@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.

BrahmanandaRao
Lapis Lazuli | Level 10
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;

hashman
Ammonite | Level 13

@BrahmanandaRao :

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.

Tom
Super User Tom
Super User

@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.

 

BrahmanandaRao
Lapis Lazuli | Level 10

@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

 

 

 

Kurt_Bremser
Super User

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.

Tom
Super User Tom
Super User

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
;;;;

image.png

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 12 replies
  • 1625 views
  • 0 likes
  • 6 in conversation