-2

need GENERIC SAS macro TO generate the PDF/Excel/RTF report from the input SAS dataset.

THE FOLLOWING are the parameters to use---->

1) indsn – Input Dataset 2) varlist – List of Variables to be printed. If none then print all variables in the dataset 3) report_type – PDF or Excel or RTF. You need to use appropriate ODS statements. 4) title1 – Title1 of the report 5) footnote1 – Footnote1 of the report 6) report_location – Physical location of the report

please help me in building a logic for the above question???

Tried do far:

data test; 
input ID var1 var2 var3 var4; 
cards; 

1 6 4 4 5 6 5 4 5 5 3 7 9 5 9
7 9 4 8 6 run; ods pdf file='/folders/myfolders/v.pdf';

proc print data=work.test; 
var ID; run; 
ods pdf close; 

%macro reportgen(indsn=,varlist=, report_type=, title1=, footnote=, report_location=); 
%local i nextword; %let dsid =%sysfunc(open(&indsn)); 
%do i=1 %to %sysfunc(countw(&varlist)); 
%let nextword = %scan(&varlist, &i); 
%end; 
%mend reportgen; 
%macro reportgen(indsn=work.test,varlist=var1 var2 var4,report_type=,title1=,footnote=,report_location);

this only half of the macro.

Reeza
  • 20,510
  • 4
  • 21
  • 38
Apache11
  • 189
  • 11
  • Your code/question has nothing proprietary in it and someone has taken the time to answer your question. Deleting it is inconsiderate. – Reeza Jan 06 '16 at 15:42

1 Answers1

0

First of all, welcome to the site!

Here is a macro that meets your needs:

*ProcessBody;
%macro reportgen(indsn=,varlist=, report_type=, title1=, footnote1=, report_location=);

    /* Windows related option */
    goptions device=actximg;

    /* Check if report path specified and abort gracefully if it isn't */
    %if "&report_location"="" %then
        %do;

            data _NULL_;
                putlog "ERROR: No destionation. Report aborted.";
            RUN;
        %GOTO done; 
        %end;

    /* If varlist present, then keep only varlist */
    %if &varlist ne %then
        %do;

            data tmp (keep= &varlist);
                set &indsn;
            run;

            %let indsn=tmp;
        %end;

    /* Close all ODS destionations before oppening the one required */
    ODS _ALL_ close;

    ODS &report_type file="&report_location";

    /* Specify Title and Footnote */ 
    %if &title1 ne %then
        %do;
            title "&title1";
        %end;

    %if &footnote1 ne %then
        %do;
            footnote "&footnote1";
        %end;

    /* Print the output */ 
    proc print data=&indsn;
    run;

    /* Completion */ 
    ODS _ALL_ close;
    %done:
%mend;

Example call:

%reportgen(indsn=sashelp.class,varlist=name,report_type=RTF,title1=Hello World!,footnote1=Goodbye World!,report_location=/home/tmp/test.RTF);
Vasilij Nevlev
  • 1,449
  • 9
  • 22
  • I am sorry, I don't understand what you have type. If you are about the windows option, it just changes the output devices which causes a warning in Win7/64 bit in some circumstances. Try removing it in your instance and see if it causes any warnings/errors for you. – Vasilij Nevlev Jan 05 '16 at 16:35