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;
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;
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.
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.