BookmarkSubscribeRSS Feed
DFHGSGSER
Calcite | Level 5

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;

1 REPLY 1
Tom
Super User Tom
Super User

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;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1429 views
  • 0 likes
  • 2 in conversation