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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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