BookmarkSubscribeRSS Feed
study_SAS
Calcite | Level 5

Dear community,

I am studying the basic data steps and still have confusion about using dsd, missover, truncover and colon modifier.  Could you please be so kind to explain to me what went wrong with my codes when reading in raw data? 

/* 1 what’s wrong with my codes? */

data Customer1;

infile datalines;

input ID $9. Name $10. Phone $14. Date mmddyy8. Price dollar8.2;

format Date mmddyy10.;

datalines;

542857845 Susan     (510)893-2541 10/10/08 $2.50

754857485 David     (415)785-9685 01/12/05 $12.2

854748578 Catherine (408)254-6523 04/03/07 $1,009

;

/* sample codes provided */

data test1;

     infile datalines;

     input SSN $9. Name $11-20 Phone $21-33 +1 Reg MMDDYY8. Amount Dollar8. ;

     format Reg MMDDYY10. ;

datalines;

542857845 Susan     (510)893-2541 10/10/08 $2.50

754857485 David     (415)785-9685 01/12/05 $12.2

854748578 Catherine (408)254-6523 04/03/07 $1,009

;

run;


/* 2 what’s wrong with my codes? */

data Customer2;

infile datalines dsd truncover;

input Name: $10. ID $9. Phone $14. Date mmddyy8. Price dollar9.2;

format Date mmddyy10.;

datalines;

Susan 542857845 (510)893-2541 10-10-08 $2.50

David 754857485 (415)785-9685 1-12-05 $12.2

Catherine 854748578 (408)254-6523 4-3-07 $1,009

;


Many thanks!

best,

Lil

6 REPLIES 6
Ksharp
Super User

You should use list input method , not formatted input method :

Phone : $14.

study_SAS
Calcite | Level 5

Thank you so much for the response, Keshan!  I will give it a try.

best,

Lil

ballardw
Super User

Note that in your first two examples that the columns of data align neatly. The formatted input on an input statement is very literal about reading the specified number of columns sometimes and the data used in your third case doesn't align.

In very many cases it is preferable to assign the informat in a separate statement from the input. Especially if your data sources have a tendency to change column widths unexpectedly which is a very common issue with name type data.

study_SAS
Calcite | Level 5

Thank you for the response!  really appreciated it.

best,

Lil

ChrisHemedinger
Community Manager

Here's a very helpful article from Charley Mullin (SAS Tech Support) on this topic:

You'll learn about DSD, TRUNCOVER, TERMSTR, DLM (delimiters), and ENCODING.

Chris

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1510 views
  • 6 likes
  • 4 in conversation