DATA Step, Macro, Functions and more

Format for Import number value

Accepted Solution Solved
Reply
Contributor
Posts: 49
Accepted Solution

Format for Import number value

Hi,

I have to import the file.csv, that contains a fields with this values:
VALUE

3456

-4567

456,8


Which is it, the best format for import that values?
Usually I use best12. , but in this case I have some trouble with the comma. I also use COMMAx.w..but it doesn't work.

I'm not able to find correct format.

Some of you has some good suggestion?

 


Accepted Solutions
Solution
‎06-24-2017 12:35 AM
Super User
Super User
Posts: 6,502

Re: Format for Import number value

BEST is a FORMAT, not an INFORMAT.  The normal numeric informat nn., which is also known as the F (I assume for FIXED?) informat works for the types of values that the BEST format produces.  If you use BEST12. as your INFORMAT then SAS will silently just use the F12. or 12. informat.  Do NOT include a decimal value on the INFORMAT because then SAS will divide any input string that does not have a period in it by that many powers of ten.

 

If your values might have embedded commas and/or dollar signs then use the COMMA (which is also known as the DOLLAR) informat to read them. That informat will first remove the commas and dollar signs and then use the normal numeric informat.

 

If your numbers are using commas for decimal places and periods for thousands separators then use the COMMAX informat.

 

data want ;
  infile cards truncover ;
  input num commax32. ;
cards;
3456
-4567
456,8
;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,631

Re: Format for Import number value

Explain what you think is the right way to import the third row which reads

 

456,8

 

because we don't know what you think should be done with this row

Solution
‎06-24-2017 12:35 AM
Super User
Super User
Posts: 6,502

Re: Format for Import number value

BEST is a FORMAT, not an INFORMAT.  The normal numeric informat nn., which is also known as the F (I assume for FIXED?) informat works for the types of values that the BEST format produces.  If you use BEST12. as your INFORMAT then SAS will silently just use the F12. or 12. informat.  Do NOT include a decimal value on the INFORMAT because then SAS will divide any input string that does not have a period in it by that many powers of ten.

 

If your values might have embedded commas and/or dollar signs then use the COMMA (which is also known as the DOLLAR) informat to read them. That informat will first remove the commas and dollar signs and then use the normal numeric informat.

 

If your numbers are using commas for decimal places and periods for thousands separators then use the COMMAX informat.

 

data want ;
  infile cards truncover ;
  input num commax32. ;
cards;
3456
-4567
456,8
;

Contributor
Posts: 49

Re: Format for Import number value

ok,

yes it works!!!


Thanks Tom.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 130 views
  • 0 likes
  • 3 in conversation