Hi All, When run the following code for imputing the date and time, I am getting the following errors. Can anyone help me what is wrong with this? Also, I do not understand why prxid variable value is showing different values whenever I execute the call statement %splitIso8601dtc( inDat= ae, outDat= ksfe_2018, var= aestdtc ). Can anyone help me to understand what is wrong with the code and how correct it? Errors are: ERROR: Invalid regular expression delimiter "p" in "prxid". Delimiter must be non-alphanumeric and non-whitespace. ERROR: The regular expression passed to the function PRXMATCH contains a syntax error. WARNING: Argument 1 to function PRXMATCH referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range. NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set to a missing value. ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: %sysfunc(prxmatch(prxid,&var)) ERROR: The macro SPLITISO8601DTC will stop executing. Sample data set for testing the code: DATA ae; length aestdtc $ 20.; aestdtc= '2017-03'; OUTPUT; aestdtc= '2017-03-01T14'; OUTPUT; aestdtc= '2017---15'; OUTPUT; aestdtc= '2017-03--T07:30'; OUTPUT; aestdtc= '2017----T07:30'; OUTPUT; RUN; proc print;run; Macro code is follows: %MACRO splitIso8601dtc( inDat= , outDat= , var= ) / DES='Macro to separate ISO 8601 datetime components'; DATA &outDat; SET &inDat; * create regular expression ID to separate is8601dt datetime components; %let prxid= %sysfunc(prxparse('/^(\d{4})(-(\d{2}|-)(-(\d{2}|-)(T(\d{2}|-)(:(\d{2}|-)(:(\d{2}))?)?)?)?)?\s*$/')); %put var is.............&var; %put prxid is ...........&prxid; %IF %sysfunc(prxmatch(prxid,&var)) %THEN %DO; * separate datetime components; &var._year= input(compress(%sysfunc(prxposn(prxid,1,&var),'-')), 4.); &var._min_month= input(compress(%sysfunc(prxposn(prxid,3,&var),'-')), 2.); &var._min_day= input(compress(%sysfunc(prxposn(prxid,5,&var),'-')), 2.); &var._min_hour= input(compress(%sysfunc(prxposn(prxid,7,&var),'-')), 2.); &var._min_minute= input(compress(%sysfunc(prxposn(prxid,9,&var),'-')), 2.); &var._min_second= input(compress(%sysfunc(prxposn(prxid,11,&var),'-')), 2.); * impute missing datetime components; * impute month when missing; %IF missing(&var._min_month) %THEN %DO; &var._min_month= 1; &var._max_month= 12; %END; %ELSE %DO; &var._max_month= &var._min_month; %END; * impute day when missing; %IF missing(&var._min_day) %THEN %DO; &var._min_day= 1; * Last day of the respective month and year; &var._max_day= day(intnx('month',input(cats(put(&var._year,z4.),'-' ,put(&var._max_month,z2.),'-01') ,is8601da.) ,0 ,'E')); %END; %ELSE %DO; &var._max_day= &var._min_day; %END; * impute hour when missing; %IF missing(&var._min_hour) %THEN %DO; &var._min_hour= 0; &var._max_hour= 23; %END; %ELSE %DO; &var._max_hour= &var._min_hour; %END; * impute minute when missing; %IF missing(&var._min_minute) %THEN %DO; &var._min_minute= 0; &var._max_minute= 59; %END; %ELSE %DO; &var._max_minute= &var._min_minute; %END; * impute second when missing; %IF missing(&var._min_second) %THEN %DO; &var._min_second= 0; &var._max_second= 59; %END; %ELSE %DO; &var._max_second= &var._min_second; %END; * create the full date/time value; FORMAT &var._min &var._max is8601dt.; &var._min= dhms(mdy(&var._min_month, &var._min_day, &var._year) ,&var._min_hour, &var._min_minute, &var._min_second); &var._max= dhms(mdy(&var._max_month, &var._max_day, &var._year) ,&var._max_hour, &var._max_minute, &var._max_second); %END; %MEND splitIso8601dtc; Calling the above marco: %splitIso8601dtc( inDat= ae, outDat= ksfe_2018, var= aestdtc ) Thanks
... View more