/*___________________________________________________________________ Ĥ MACRO: MONTHLY Ĥ Ĥ JOB: Data Quality Ĥ Ĥ PROGRAMMER: Mahmoud Azimaee Ĥ Ĥ DATE: October 2011 Ĥ Ĥ DESCRIPTION: This Macro creates a monthly based format to be Ĥ Ĥ used on a SAS Date variable. The format will be Ĥ Ĥ saved as a SAS file in /dq/saswork/[USERNAME]/ Ĥ Ĥ under the name 'temp_monthly.sas'. Ĥ Ĥ Use %include 'temp_monthly.sas' in your programs Ĥ Ĥ to call it. The format name is 'monthly.'. Ĥ Ĥ PARAMETERS: STARTYR= First part of the starting fiscal year Ĥ Ĥ ENDYR= First part of the ending fiscal year Ĥ Ĥ EXAMPLE: %monthly(1992,2009); Ĥ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ*/ **********************************************************************; %Macro monthly(startyr,endyr); %PUT ___________________________________________________________________; %PUT Ĥ Manitoba Centre for Health policy (MCHP) Ĥ; %PUT Ĥ MACRO: MONTHLY Ĥ; %PUT Ĥ JOB: Data Quality Ĥ; %PUT Ĥ PROGRAMMER: Mahmoud Azimaee Ĥ; %PUT Ĥ DATE: October 2011 Ĥ; %PUT Ĥ Running for: &STARTYR - &ENDYR ; %PUT ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ; data month; month='Jan'; nextmonth='Feb'; m=1; output; month='Feb'; nextmonth='Mar'; m=2; output; month='Mar'; nextmonth='Apr'; m=3; output; month='Apr'; nextmonth='May'; m=4; output; month='May'; nextmonth='Jun'; m=5; output; month='Jun'; nextmonth='Jul'; m=6; output; month='Jul'; nextmonth='Aug'; m=7; output; month='Aug'; nextmonth='Sep'; m=8; output; month='Sep'; nextmonth='Oct'; m=9; output; month='Oct'; nextmonth='Nov'; m=10; output; month='Nov'; nextmonth='Dec'; m=11; output; month='Dec'; nextmonth='Jan'; m=12; output; run; data month; set month; startnum=SYMGETN('startyr'); endnum=SYMGETN('endyr'); yrs=endnum - startnum; do year=startnum to endnum; format='"01' || month || put(year,$4.) ||'"d - "01' || nextmonth || put(year,$4.) || '"d = "' || upcase(month)||put(year,$4.) || '"' ;; if month='Dec' then do; format='"01' || month || put(year,$4.) ||'"d - "01' || nextmonth || put(year+1,$4.) || '"d = "' || upcase(month)||put(year,$4.) || '"' ;; end; output; end; run; proc sort data=month; by year m; run; data _null_ ; file "/dq/saswork/&spdsuser/temp_monthly.sas" ; /*where /dq/saswork/&spdsuser is the directory to save temp_monthly.sas*/ set month end=last; if _n_=1 then do; put 'proc format;'; put 'value monthly'; end; put format; if last then put "other = 'Other Years';"; run; proc datasets library=work ; delete month; run; quit; %Mend monthly;