Help using Base SAS procedures

Read following date formats

Reply
Contributor
Posts: 52

Read following date formats

Hi,

Can you tell which sas format to use for reading following dates:

1. 12-JAN-14

2. 12-JAN-2014

Thanks

Trusted Advisor
Posts: 1,228

Re: Read following date formats

Posted in reply to dkanand86

data have;

input (date1 date2) (:anydtdte.);

format date1 date2 date9.;

datalines;

12-JAN-14 12-JAN-2014

;

Contributor
Posts: 52

Re: Read following date formats

I want to view date1 as 12-JAN14 and not as 12-JAN-2014.

Can you suggest a format which can do this?

Respected Advisor
Posts: 3,799

Re: Read following date formats

Why not DATE.?

Contributor
Posts: 52

Re: Read following date formats

Posted in reply to data_null__

No, date. does not work, as it gives same output. Pls help.

Untitled.png

PROC Star
Posts: 7,467

Re: Read following date formats

Posted in reply to dkanand86

proc format;

  picture datex (default = 8)

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

     (datatype = date);

run;

data have;

input (date1 date2) (:anydtdte.);

format date1 datex.;

format date2 date9.;

datalines;

12-JAN-14 12-JAN-2014

;

Contributor
Posts: 52

Re: Read following date formats

Just tweaked a bit!

its works now. Thanks!

proc format;

  picture datex (default = 10)

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

     (datatype = date);

run;

data have2;

input (date1 date2) (:anydtdte.);

format date1 datex.;

format date2 date9.;

datalines;

12-JAN-14 12-JAN-2014

;

Contributor
Posts: 52

Re: Read following date formats

Posted in reply to dkanand86

The following code is giving a date format issue:

I have created format (named datex) for loan_issue_date variable. But, when i run following code, the code gives error stating "DATEX format not found". Please help.!

Code:

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

  picture datex (default = 10)

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

     (datatype = date);

run;

options fmtsearch=(deep work);

data deep.customer_loan_detail;

    infile cards;

    input

cust_id 4.

acct_number $8.

customer_loan_type : $8.

loan_issue_date anydtdte.

loan_amount 5.

loan_flag $3.;

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;

PROC Star
Posts: 7,467

Re: Read following date formats

Posted in reply to dkanand86

You're confusing formats with informats. I think you are trying to accomplish something like the following:

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

  picture datex (default = 9)

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

     (datatype = date);

run;

options fmtsearch=(deep work);

data deep.customer_loan_detail;

    infile cards;

    input

cust_id

acct_number $8.

customer_loan_type : $8.

loan_issue_date anydtdte9.

loan_amount

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

;

Contributor
Posts: 52

Re: Read following date formats

Posted in reply to dkanand86

The following code is giving a date format issue:

I have created format (named datex) for loan_issue_date variable. But, when i run following code, the code gives error stating "DATEX format not found". Please help.!

Code:

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

  picture datex (default = 10)

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

     (datatype = date);

run;

options fmtsearch=(deep work);

data deep.customer_loan_detail;

    infile cards;

    input

cust_id 4.

acct_number $8.

customer_loan_type : $8.

loan_issue_date datex.

loan_amount 5.

loan_flag $3.;

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: 27

Re: Read following date formats

Posted in reply to dkanand86

As mentioned by Arthur, you are creating a format and using it as informat in the input statement and that's why you are getting the error.

The error message that you get in your code is about informat.

ERROR 48-59: The informat DATEX was not found or could not be loaded.

Ask a Question
Discussion stats
  • 10 replies
  • 378 views
  • 0 likes
  • 5 in conversation