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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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