BookmarkSubscribeRSS Feed
AlexeyS
Pyrite | Level 9
data cars;
INFILE DATALINES dlm=',';
input Make : $9. Invoice : comma6.;
datalines;
BMW,35,681
Chevrolet,28,197
;
run;

Why I can't read Invoice correctly? What's wrong?

Thank you

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

You are using a comma both as a delimiter and as a digit separator in your data. Not a good idea. You could do something like this

 

data cars;
INFILE DATALINES dlm='|';
input Make : $9. Invoice : comma6.3;
datalines;
BMW|33,890
Chevrolet|17,234
Ford|14,482
Infinity|27,536
;
run;
Kurt_Bremser
Super User

It contains a delimiter. Delimiters take precedence over commas used as a decimal point.

Use a different delimiter or "mask" the commas with quotes and the dsd option:

data cars;
INFILE DATALINES dlm=',' dsd;
input Make : $9. Invoice : comma6.;
datalines;
BMW,"33,890"
Chevrolet,"17,234"
Ford,"14,482"
Infinity,"27,536"
;
run;
AlexeyS
Pyrite | Level 9

You want to say, that i cannot read a raw data as i wrote?

Why i ask, because i saw a lot of palces, where they write it as me, but it doen't work.

for example, https://onlinecourses.science.psu.edu/stat481/node/60/

AlexeyS
Pyrite | Level 9

you are right, excuse me

Tom
Super User Tom
Super User

If the field with the embedded delimiter is the last one in the line then just read that field using formatted input instead of list mode input.  Just remove the colon modifier before the format specification in the INPUT statement.

data cars;
  INFILE DATALINES dlm=',' dsd truncover;
  input Make  :$9. Invoice comma6.;
datalines;
BMW,35,681
Chevrolet,28,197
;

If the field is in the middle of the line then you will need to work harder to figure out which parts belong to which fields.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1273 views
  • 0 likes
  • 4 in conversation