I am using a Date Prompt to get a user input month in SAS. I get the input in the following format: UserSelectedMonth = DDMMMYYYY (eg: 01JUL2022) – This is the macro variable obtained from prompt. UserSelectedMonth in the MMM-YY format Selected_month = JUL-22 – This must be a macro variable From the UserSelectedMonth, I want to find the number corresponding to the month Selected_month_no = 7 (eg: July is the 7th month) ---- This must be a macro variable Extract the three-letter name of the above UserSelectedMonth Selected_month_name = JUL ---- This must be a macro variable Find the year from the UserSelectedMonth as a two-digit number Selected_year = 22 ---- This must be a macro variable Find the same month in 2019 in the MMMYY format Month_year_19 = JUL19 ---- This must be a macro variable Previous month in the MMMYY or MMMYYYY format Previous_month = JUN22 or Previous_month = JUN2022 ---- This must be a macro variable I need to read some automatically generated files having different file name formats, so based on the user input I need all these variables to dynamically define the files names and read them inside a program. Can someone please help me to obtain the above? I tried and my code does not work ☹️ Sorry for the long post. Thanks for anyone giving some help! ====================================================================================================================== My code: data _null_; /* UserSelectedMonth is obtained from the Date prompt as a macro variable, but I just stated here so that that the rest of the code can be tested*/ %let UserSelectedMonth = 01JUL2022; /*Try to obtain the Selected_month_no as a two digit no using the z2. format*/ %let Selected_month_no = %sysfunc(month("&UserSelectedMonth."d), z2.); /*Try to obtain the Selected_month_name in three letters using the monname3. format*/ %let Selected_month_name = %sysfunc(month("&UserSelectedMonth."d), monname3.); /*Extract the last two digits (Selected_year) using substr from DDMMMYYYY*/ %let Selected_year = %sysfunc(substr("&UserSelectedMonth",8,2)); /*Obtain Month_year_19 by combining Selected_month_name and 19*/ %let Month_year_19 = %sysfunc(cat(&Selected_month_name,19)); /*Obtain Selected_month by combining Selected_month_name, "-" and Selected_year */ %let Selected_month =%sysfunc(cat(&Selected_month_name,-,&Selected_year)); /*Obtain previous month from */ Previous_month = intnx('MONTH', "&UserSelectedMonth"d, -1, 'BEGINNING'); format Previous_month date9.; call symputx('Previous_month ', put(Previous_month ,date9.)); %put _user_; run; ======================================================================= Macro variables I am getting: GLOBAL MONTH_NAME Jan GLOBAL MONTH_NO 07 GLOBAL MONTH_YEAR_19 Jan19 GLOBAL SELECTEDMONTH 01Jul2022 GLOBAL SELECTEDMONTH_END 31Jul2022 GLOBAL SELECTEDMONTH_LABEL Previous month GLOBAL SELECTEDMONTH_REL M-1M GLOBAL SELECTED_MONTH Jan-2 GLOBAL SELECTED_MONTH_NAME Jan GLOBAL SELECTED_MONTH_NO 07 GLOBAL SELECTED_YEAR 02
... View more