BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rakeon
Quartz | Level 8

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Tom
Super User Tom
Super User

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
;

Rakeon
Quartz | Level 8

ok,

yes it works!!!


Thanks Tom.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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