A possibly not quite silly question: is your variable DATETIME a character value? If not and the value is an actual SAS datetime value then you likely are not going to get the desired result:
Example with a SAS datetime value.
data example;
datetime_='01JAN2019:12:12:12'dt;
format datetime_ datetime20.;
x=substr(datetime_,7,4);
y=substr(datetime_,4,2);
run;
Which yields 9639 and 86.
If your datetime_ is character, why? SAS provides a large number of tools to extract pieces of information from date, datetime and time valued variables. It appears that you might be attempting to compare a year of 2018 and month of 08.
data example;
datetime_='01AUG2018:12:12:12'dt;
format datetime_ datetime20.;
if put(datepart(datetime_),yymmn6.)='201808' then put "Found It!";
run;
For one example. I could create a custom format for use with DATETIME values to show only year and month without the extraction of the date portion of a datetime value.
... View more