Help using Base SAS procedures

please help with troubleshooting: reading raw data into SAS, confusion about use of dsd, truncover, etc.

Reply
New Contributor
Posts: 4

please help with troubleshooting: reading raw data into SAS, confusion about use of dsd, truncover, etc.

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

Super User
Posts: 10,018

Re: please help with troubleshooting: reading raw data into SAS, confusion about use of dsd, truncover, etc.

Posted in reply to study_SAS

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

Phone : $14.

New Contributor
Posts: 4

Re: please help with troubleshooting: reading raw data into SAS, confusion about use of dsd, truncover, etc.

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

best,

Lil

Super User
Posts: 11,343

Re: please help with troubleshooting: reading raw data into SAS, confusion about use of dsd, truncover, etc.

Posted in reply to study_SAS

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.

New Contributor
Posts: 4

Re: please help with troubleshooting: reading raw data into SAS, confusion about use of dsd, truncover, etc.

Thank you for the response!  really appreciated it.

best,

Lil

Community Manager
Posts: 2,952

Re: please help with troubleshooting: reading raw data into SAS, confusion about use of dsd, truncover, etc.

Posted in reply to study_SAS

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

New Contributor
Posts: 4

Re: please help with troubleshooting: reading raw data into SAS, confusion about use of dsd, truncover, etc.

Posted in reply to ChrisHemedinger

Thanks Chris for the article!  It helped.

Best,

Lil

Ask a Question
Discussion stats
  • 6 replies
  • 270 views
  • 6 likes
  • 4 in conversation