Learning SAS? Welcome to the exclusive online community for all SAS learners.

Unable to read properly "loan_amount" variable!

Reply
Contributor
Posts: 52

Unable to read properly "loan_amount" variable!

Hi,

I am unable to read properly loan_amount variable.

Two Problems:

1. In loan_issue_date variable, the leading zeroes is getting truncated.

2. In loan_amount variable, the values are not fully read and trailing digits are read in the next variable.

I dont know the reason why this is happening?

proc format library=deep fmtlib cntlout=deep.fmts;

  picture datex (default = 9)

    low-high = '%d-%b-%y'

     (datatype = date);

run;

data deep.customer_loan_detail_new;

    infile datalines;

    input

cust_id 4.

acct_number $8.

customer_loan_type : $8.

loan_issue_date  date9.

loan_amount 10.

loan_flag $3.;

format loan_issue_date datex.;

datalines;

1034 C734459 CAR 05-APR-12 22789 YES

2498 C657568 HOME 05-MAR-12 100387 YES

6523 C673121 HOME 04-SEP-05 87982 YES

8677 C367420 HOME 19-SEP-13 35876 YES

5487 C784509 CAR 02-AUG-11 14990 YES

8496 C741298 PERSONAL 12-JUL-10 5500 YES

;

run;

SAS Employee
Posts: 8

Re: Unable to read properly "loan_amount" variable!

Try this:

data customer_loan_detail_new;

    infile datalines;

    input cust_id acct_number $ customer_loan_type $ loan_issue_date date9. loan_amount loan_flag $;

    format loan_issue_date date9.;

datalines;

1034 C734459 CAR 05-APR-12 22789 YES

2498 C657568 HOME 05-MAR-12 100387 YES

6523 C673121 HOME 04-SEP-05 87982 YES

8677 C367420 HOME 19-SEP-13 35876 YES

5487 C784509 CAR 02-AUG-11 14990 YES

8496 C741298 PERSONAL 12-JUL-10 5500 YES

;

run;

Contributor
Posts: 52

Re: Unable to read properly "loan_amount" variable!

Thanks.

But, why it was not running earlier?

Super User
Posts: 10,538

Re: Unable to read properly "loan_amount" variable!

When you specified the 10. format on the input it basically  reads 10 columns starting from the end of the previous variable (date) which included the first letter or two of the flag variable. This is sort of left over behavior from ancient days and something called an implied decimal where you would read a text value such as 12345678 with an 8.2 format and would be read in as 123456.78. If the format isn't on the input statement then defaults to best and that would work.

Valued Guide
Posts: 3,208

Re: Unable to read properly "loan_amount" variable!

There as a lot the input statement can do on all types of input.  There is list input variable and formatted.

Using a CVS (DSD) files is ignoring the length's of all formats as the separation char is doing that.

SAS(R) 9.4 Statements: Reference, Third Edition (list input)

SAS(R) 9.4 Statements: Reference, Third Edition (formatted input)

If you use the formatted / with columns instead of the list with variable lengths it will do so.  That was you first attempt.

It not really outdated it one of the safest ways- to handle column oriented data. A RDBMS is columns oriented.

The disadavantage of not working column oriented may be outdated. That disadvantage is all that space overhead by spaces. There are enough compression methods now and storage is becoming cheaper an cheaper.

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 4 replies
  • 349 views
  • 0 likes
  • 4 in conversation