BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

In Example1  I enter a date data as a character

 

Data Example1;
input ID 1
Loan_ID 3
Sum_Loan 5-7
Interest 9-11
date_Loan $ 13-22 ;
Cards;
1 1 100 2.4 01/06/2018
;
run;

 

 

In Example2  I am trying to enter a date data as sas numeric and I get empty values.Why????

Data  Example2;
input ID 1
Loan_ID 3
Sum_Loan 5-7
Interest 9-11
date_Loan 13-22 ;
Cards;
1 1 100 2.4 01/06/2018
;
run;

2 REPLIES 2
Kurt_Bremser
Super User

SAS does not automatically recognize a date (or a time value) as such, so you need to give it an informat:

data  example2;
input
  ID
  Loan_ID
  Sum_Loan
  Interest
  date_Loan :ddmmyy10.
;
format date ddmmyy10.;
cards;
1 1 100 2.4 01/06/2018
;
run;
Tom
Super User Tom
Super User

If you want SAS to read '01/06/2018' as the first of june 2018 then use the DDMMYY informat. If instead you want it to treat that as the sixth of January then use the MMDDYY informat.  Either way make sure to attach a format so that SAS doesn't display the date as the raw number of days since the beginning of 1960.

 

data Example1;
  input
    ID 1
    Loan_ID 3
    Sum_Loan 5-7
    Interest 9-11
    @13 date_mdy mmddyy10.
    @13 date_dmy ddmmyy10.
  ;
  format date: date9. ;
cards;
1 1 100 2.4 01/06/2018
;

 

In future it might be best to store your date strings in either Year, Month, Day order or use SAS's DATE format and avoid the confusion.

image.png

 

 

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 600 views
  • 0 likes
  • 3 in conversation