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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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