data week_formats;
input fmtname $ :20. start $ label $;
type='C';
cards;
week_one_fmt 01 52
week_one_fmt 02 04
week_one_fmt 03 08
week_one_fmt 04 12
week_one_fmt 05 17
week_one_fmt 06 21
week_one_fmt 07 25
week_one_fmt 08 30
week_one_fmt 09 34
week_one_fmt 10 38
week_one_fmt 11 43
week_one_fmt 12 47
week_two_fmt 01 06
week_two_fmt 02 10
week_two_fmt 03 14
week_two_fmt 04 19
week_two_fmt 05 23
week_two_fmt 06 27
week_two_fmt 07 32
week_two_fmt 08 36
week_two_fmt 09 40
week_two_fmt 10 45
week_two_fmt 11 49
week_two_fmt 12 01
;
run;
proc format cntlin=week_formats;
run;
%let mth_code = 202304;
%let current_year = 2023;
%let prev_year = 2022;
%let next_year = 2024;
data CMAP_sample;
if input(substr("&mth_code", 5, 2), 8.) in (1:12) then do;
week1 = catt("¤t_year", put(trim(substr("&mth_code", 5, 2)), week_one_fmt.));
week2 = catt("¤t_year", put(trim(substr("&mth_code", 5, 2)), week_two_fmt.));
end;
run;
@Lkrem wrote:
Hi @Community_Help ! Looking for help with the code below. I created some macros and I am trying to call the macro in either the data step or the proc sql (just need one of them), but cannot get this to work. Any guidance would be greatly appreciated!
%let mth_code = 202301; %let current_year = 2023; %let prev_year = 2022; %let next_year = 2024; %MACRO Week1; if substr(put(&mth_code.,6.),5,2) = '01' then Week1 = (cats(&prev_year.,'52'))*1; else if substr(put(&mth_code.,6.),5,2) = '02' then Week1 = (cats(¤t_year.,'04'))*1; else if substr(put(&mth_code.,6.),5,2) = '03' then Week1 = (cats(¤t_year.,'08'))*1; else if substr(put(&mth_code.,6.),5,2) = '04' then Week1 = (cats(¤t_year.,'12'))*1; else if substr(put(&mth_code.,6.),5,2) = '05' then Week1 = (cats(¤t_year.,'17'))*1; else if substr(put(&mth_code.,6.),5,2) = '06' then Week1 = (cats(¤t_year.,'21'))*1; else if substr(put(&mth_code.,6.),5,2) = '07' then Week1 = (cats(¤t_year.,'25'))*1; else if substr(put(&mth_code.,6.),5,2) = '08' then Week1 = (cats(¤t_year.,'30'))*1; else if substr(put(&mth_code.,6.),5,2) = '09' then Week1 = (cats(¤t_year.,'34'))*1; else if substr(put(&mth_code.,6.),5,2) = '10' then Week1 = (cats(¤t_year.,'38'))*1; else if substr(put(&mth_code.,6.),5,2) = '11' then Week1 = (cats(¤t_year.,'43'))*1; else if substr(put(&mth_code.,6.),5,2) = '12' then Week1 = (cats(¤t_year.,'47'))*1; else Week1 = 0; %MEND; %MACRO Week2; if substr(put(&mth_code.,6.),5,2) = '01' then Week2 = (cats(¤t_year.,'06'))*1; else if substr(put(&mth_code.,6.),5,2) = '02' then Week2 = (cats(¤t_year.,'10'))*1; else if substr(put(&mth_code.,6.),5,2) = '03' then Week2 = (cats(¤t_year.,'14'))*1; else if substr(put(&mth_code.,6.),5,2) = '04' then Week2 = (cats(¤t_year.,'19'))*1; else if substr(put(&mth_code.,6.),5,2) = '05' then Week2 = (cats(¤t_year.,'23'))*1; else if substr(put(&mth_code.,6.),5,2) = '06' then Week2 = (cats(¤t_year.,'27'))*1; else if substr(put(&mth_code.,6.),5,2) = '07' then Week2 = (cats(¤t_year.,'32'))*1; else if substr(put(&mth_code.,6.),5,2) = '08' then Week2 = (cats(¤t_year.,'36'))*1; else if substr(put(&mth_code.,6.),5,2) = '09' then Week2 = (cats(¤t_year.,'40'))*1; else if substr(put(&mth_code.,6.),5,2) = '10' then Week2 = (cats(¤t_year.,'45'))*1; else if substr(put(&mth_code.,6.),5,2) = '11' then Week2 = (cats(¤t_year.,'49'))*1; else if substr(put(&mth_code.,6.),5,2) = '12' then Week2 = (cats(&next_year.,'01'))*1; else Week2 = 0; %MEND;
data CMAP_sample; set cmap.Data; %Week1; %Week2; Keep CB_CUST_ID WEEK_CODE CNT_OPN_AUTO where WEEK_CODE >= Week1 and WEEK_CODE <= Week2; run;
proc sql; %Week1; %Week2; CREATE TABLE CMAP_sample AS select a.CB_CUST_ID as CUST_ID, a.WEEK_CODE, a.CNT_OPN_AUTO, a.CNT_OPN_MORT, from cmap.Data a where (a.WEEK_CODE >= Week1 and a.WEEK_CODE <= Week2) ; quit;
... View more