Way too much work on the tmonth (as long as the first day of the month is acceptable)
tmonth=input(YrMth,yymmn6.);
if the Yrmth is character, which is not what the OP said at the start of this.
@jebjur wrote:
Converting a character string of '202201' to numeric is still not a SAS date value, so you won't be able to extract the year, quarter, etc. A SAS date is the number of days since January 1, 1960. In order to create a true SAS date, you can use the MDY function, along with the SUBSTR and PUT functions to parse out the year and month and convert to numeric, and then add a 'day' value of 1 for example:
data tab ;
YrMth='201202';
tmonth=MDY(put(substr(YrMth,5),2.),1,put(substr(YrMth,1,4),4.)); /* create a numeric SAS date value */
year = year(tmonth);
Quarter = "Q" || put(QTR(tmonth),1.);
yr = put (year,z4.);
inc_mnth = put(year(tmonth),z4.) || put(month(tmonth),z2.);
month2=put(put(month(tmonth),z2.), $mth.);
format tmonth yymm6.;
run;
Does that help?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.