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
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;
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;
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/
In that example page, they never use a comma as delimiter.
you are right, excuse me
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.
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!
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.