DATA Step, Macro, Functions and more

Date Format YYMMDD to MMDDYY error

Reply
New Contributor
Posts: 2

Date Format YYMMDD to MMDDYY error

I have raw data to import with dates in the YYMMDD10. format (2017-08-12). That is to say that my raw data in the text file appears like that, so I have to use that informat. I want to be able to import the files and convert the dates to the MMDDYY10. format (08/12/2017) and also be able to use numeric operations (if mydate < '2017JUL12'D). 

 

I am easily able to change the format so that the data in the SAS table looks correct, but when trying to use numeric operations I get:

 

ERROR: Invalid date/time/datetime constant '2017JUL12'D.

 

Sample code: 

 


DATA dsn ;
INFILE 'C:/mylocation/myfile.TXT' DELIMITER='09'X MISSOVER DSD LRECL=32767 FIRSTOBS=2 ;
INFORMAT BLACKBERRY_FLAG $1. ;
INFORMAT IPHONE_FLAG $1. ;
INFORMAT SMART_PHONE_FLAG $1. ;
INFORMAT IPAD_FLAG $1. ;
INFORMAT TABLET_FLAG $1. ;
INFORMAT COR_DGL_DP_LOC_KEY_STORE_DSTN1 BEST32. ;
INFORMAT ACCT_NBR $11. ;
INFORMAT SUBSCRIBER_ACT_DATE YYMMDD10. ;
INFORMAT REGULAR_CONTRACT_START_DATE YYMMDD10. ;
INFORMAT REGULAR_CONTRACT_END_DATE YYMMDD10. ;
INFORMAT CONTRACT_STATUS $15. ;

FORMAT BLACKBERRY_FLAG $1. ;
FORMAT IPHONE_FLAG $1. ;
FORMAT SMART_PHONE_FLAG $1. ;
FORMAT IPAD_FLAG $1. ;
FORMAT TABLET_FLAG $1. ;
FORMAT ACCT_NBR $11. ;
FORMAT SUBSCRIBER_ACT_DATE MMDDYY10. ;
FORMAT REGULAR_CONTRACT_START_DATE MMDDYY10. ;
FORMAT REGULAR_CONTRACT_END_DATE MMDDYY10. ;
FORMAT CONTRACT_STATUS $15. ;
INPUT
BLACKBERRY_FLAG $
IPHONE_FLAG $
SMART_PHONE_FLAG $
IPAD_FLAG $
TABLET_FLAG $
ACCT_NBR $
SUBSCRIBER_ACT_DATE
REGULAR_CONTRACT_START_DATE
REGULAR_CONTRACT_END_DATE
CONTRACT_STATUS $
;


RUN;

 

DATA dsn2;
SET dsn;
IF SUBSCRIBER_ACT_DATE< '2017JUL12'D;
RUN;

Super User
Super User
Posts: 7,844

Re: Date Format YYMMDD to MMDDYY error

Posted in reply to DFHGSGSER

Date literals use the DATE format.  It does not matter what format (if any) you have attached to the variable.

data dsn2;
  set dsn;
  if SUBSCRIBER_ACT_DATE< '12JUL2017'D;
run;

 

Ask a Question
Discussion stats
  • 1 reply
  • 94 views
  • 0 likes
  • 2 in conversation