Hello, I would like to invoke the macro function dynamically using the data from SQL table but i am not sure why the last part of my code is not working. %let start_date = '31Mar2008'd; %let end_date = '30Apr2008'd; DATA work.TMP_1; FORMAT start_dt DATETIME.; FORMAT end_dt DATETIME.; FORMAT stdt DATE9.; start_dt=DHMS(&start_date,0,0,0); end_dt= DHMS(&end_date,0,0,0); date_dif = intck('month',datepart(start_dt), datepart(end_dt)); /* stdt = intnx('month',datepart(start_dt),1,'same');*/ RUN; PROC SQL NOPRINT; SELECT date_dif INTO: COUNT_VAR FROM WORK.TMP_1; QUIT; %LET COUNT_VAR=%TRIM(&COUNT_VAR.); %PUT &COUNT_VAR.; PROC SQL NOPRINT; DROP TABLE work.TMP2; CREATE TABLE work.TMP2 ( date NUM FORMAT = DATE9.); QUIT; %MACRO test (COUNT_VAR=); %DO I=0 %TO &COUNT_VAR.; PROC SQL; INSERT INTO tmp2 SELECT intnx('month',datepart(start_dt),&i,'same') AS date FORMAT=DATE9. FROM TMP_1; QUIT; %END; %MEND DEFAULT_12_MONTH; OPTIONS MPRINT; %test(COUNT_VAR=&COUNT_VAR.); data tmp2; set tmp2; format cohort DATETIME.; cohort = DHMS(date,0,0,0); run; proc sql ; create table cohort_table as select '12' as period , INPUT(PUT(DATEPART(cohort),YYMMN6.), Z6.) AS start_date from tmp2; quit; PROC SQL NOPRINT; SELECT start_date INTO :ST_DT_1 - :ST_DT_%eval(&COUNT_VAR.+1) FROM cohort_table; QUIT; %put &st_dt_1.; %macro myprep(period,start_date); %put . %put &start_date; %mend myprep; data _null_; DO j = 1 to &count_var.; %myprep(12,&st_dt_j); end; run;
... View more