If you don't have a day within the month, select the first of the month.
Use actual SAS dates (which are integers that represent the number of days since 01JAN1960). When you read in something like 202107 using informat of YYMMN6. this converts it to an actual SAS date. Do not try to do this with text strings, and do not leave 202107 as 202107. Use actual SAS dates.
Then, you can use the INTCK function to determine the number of months since April 2019. Do not try to write a function on your own that determines number of months since a certain date. SAS has done the hard work for you, so you don't have to figure out how many months are between two dates.
Example:
data fakedata;
input fake_date yymmn6.;
format fake_date yymms7.;
cards;
202101
202107
;
data want;
/* Compute months since April 2019 */
set fakedata;
months = intck('month','01APR2019'd,fake_date);
run;
--
Paige Miller