You use different tables in data step and proc report. You use quotes instead of quoting functions. You dont use delimiters with the %scan and countw functions You manipulate the &i variable in the loop. You do not delete the labtabs table at the end of each loop May be this code will solve the problem. %macro CreateLabTab(paramlist,headerlist); /* Declaring of local used variables */ %local i param header count Nobs; /* Quoting of Parameters */ %let paramlist = %BQuote(¶mlist.); %let headerlist = %BQuote(&headerlist.); /* Sorting the data into temporary tables */ Proc sort data = data1 out = work._T_&sysmacroname.1; by pt; run; Proc sort data = data2 out = work._T_&sysmacroname.2; by pt; run; /* Counting the number of loops , defining the space as delimiter */ %let count = %sysfunc(countw(¶mlist., %str( ))); %do i = 1 %to &count.; /* Initialize the number of obs in the resulting dataset */ %let Nobs = 0; /* Splitting the parameterlists with delimiter and showing the results to the log */ %let param = %scan(¶mlist. , &i, %str( )); %let header = %scan(&headerlist., &i, %str(,)); %put; %put %Str(Parameter &i.); %put %str( Param : ¶m.); %put %str( Header: &header.); /* Numbering the tables (or creating a third temporary table and deleting at the end of the loop) */ data labtabs&i.; retain nobs 0; merge _T_&sysmacroname.1 _T_&sysmacroname.2 end=done; by pt; /* Standardization of the texts with upcase, count the number of hits and output*/ if Upcase(LPARM) = Upcase("¶m") then do; Nobs + 1; *********FLUFF******; output; end; /* saving the number of obs in the resulting Dataset */ if done then call symputx("Nobs",Nobs); run; /* Generate report */ %if &Nobs. > 0 %then %do; proc report nowd data=labtabs&i. headline headskip split='/'; column ('Patient' idvar) ("Title" groupnum) ("&header" time, (lvalue)) dummy; define idvar/ group order = data left ''; define groupnum/group order = data center ''; define time/across center '' order = data; define lvalue/ center ''; define dummy/ noprint; run; %end; /* end of %if &Nobs. > 0 */ %else %do; %put NOTE: Dataset Labtabs&i. has no data; %put NOTE: Do not generate report; %end; /* end of %else case from %if &Nobs. > 0 */ %end; /* end of %do i = 1 %to &count. */ /* deleting the temporary tables */ proc datasets nolist nodetails; delete _T_&sysmacroname.1 _T_&sysmacroname.2; run; quit; %mend; %let paramlist = ALK_PHOS_SER AST_SGOT_SER; %let headerlist=Alkaline phosphatase (U/L),ALT (mg/dL); %CreateLabTab(¶mlist.,%bquote(&headerlist.));
... View more