BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

The data set that is created is not correct.

As can see the values of the amount field are not correct.

Why did it happen? How can solve it ?

data one;
infile datalines truncover dsd;
input item : $6. amount comma5.;
datalines;
trucks 1,382
vans   1,235
sedans 2,391
;
run;
4 REPLIES 4
Ronein
Meteorite | Level 14

In the output data set I see values:

382
235
391

instead of :

1382

1235

2391

 

 

Kurt_Bremser
Super User

What you do depends on the exact format of your input.

If you have fixed columns (as your initial post suggests), you should use those:

data one;
input @1 item :$6. @8 amount :comma5.;
datalines;
trucks 1,382
vans   1,235
sedans 2,391
;
run;

If in fact, you have the blank as a delimiter, it should look like this:

data one;
infile datalines truncover dlm=' ' dsd;
input item : $6. amount :comma5.;
datalines;
trucks 1,382
vans 1,235
sedans 2,391
;
run;

Note that there is only a single blank in each input line.

Tom
Super User Tom
Super User

Your data lines are not properly formatted for use with the DSD option.  If you are using the DSD option and a value contains the delimiter then that value should be in quotes.  Since you didn't specify a delimiter the use of DSD also changes from space to comma as the delimiter.  So remove the DSD option.

You should also include the : modifier so that it reads the data using list mode instead of formatted mode.

data one;
  infile datalines truncover;
  input item : $6. amount :comma.;
datalines;
trucks 1,382
vans   1,235
sedans 2,391
;

Note there is no need for a width on the in-line informat when using list mode as the INPUT statement will ignore your width and instead use the width of the actual next word to be read.  The width on the informat for ITEM will force SAS to guess that you meant to create ITEM as a character variable (because of the use of a character informat) and that you wanted it to use 6 bytes instead of the default 8 bytes.

 

Also there is no need for the RUN statement after the end of your data step.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1049 views
  • 1 like
  • 3 in conversation