Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MACRO & PROC FREQ

Status
Not open for further replies.

Zeth77

MIS
Jun 25, 2008
5
TH
Can anyone inform me how to pass parameters to the macro more than one time without calling the macro multiple times??

Here is 2 macros, first to create a PDF and second one to do the procure. (Need the fist macro to let all the outputs are on one pdf file)


/****************************/
/* FREQ MACRO */
/****************************/


%macro fre_pdf;
ods listing close;

ods pdf file="C:\FREQ.pdf";
options nobyline nodate;

%macro fre(fre1 =,
fre11 =);

proc freq data=one_hundred;
tables &fre1 * &fre11 / chisq;
title "&fre1 * &fre11";
run;

%mend;

%fre(fre1 = a,
fre11 = a);

%fre(fre1 = c,
fre11 = d);

%fre(fre1 = e,
fre11 = f);

%fre(fre1 = g,
fre11 = h);

%fre(fre1 = l,
fre11 = m);

%fre(fre1 = n,
fre11 = o);

ods pdf close;
ods pdf(id=d3dstyle) close;

%mend;

%fre_pdf;
 
Hi zeth,

I think the best way to handle this is to pass all the parameters to the macro in one go, and then loop through the parameters.

You can use the parmbuff option to make your macro flexible so you can pass as many parameters as you want to your macro, then reference them using the automatic macro variable &syspbuff.

The code below should work for your example.

As a comma separator was used for the arguments, you have to make sure proper macro quoting is done (i.e using qscan, qsysfunc and bquote). HTH


%macro fre_pdf()/PARMBUFF;

ods listing close;
ods pdf file="C:\FREQ.pdf";
options nobyline nodate;

%* Strip off brackets from syspbuff;
%let y=%qsysfunc(compress(&syspbuff,'()'));
%let i=1;
%do %until (&x.= );
%* Extract arguments between commas and assign to variable x;
%let x=%qscan(%bquote(&y), &i, %str(,));
proc freq data=one_hundred;
tables &x / chisq;
title "&x";
run;
%let i=%eval(&i+1);
%end;

ods pdf close;
ods pdf(id=d3dstyle) close;

%mend fre_pdf;


%fre_pdf(a * a,c * d,e * f,g * h,l * m,n * o)
 
THANK YOU but,....

NOTE: Line generated by the invoked macro "FRE_PDF".
7 proc freq data=one_hundred; tables &x / chisq; title "&x";
-
22
7 ! run;
ERROR: Variable NAME not found.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

NOTE: ODS PDF printed 4 pages to C:STATS_GRAPH\FREQ.pdf.

ERROR 22-322: Syntax error, expecting one of the following: a name, _ALL_, _CHARACTER_, _CHAR_,
_NUMERIC_.

gives me the output but, not understand the ERROR message!!!


 
It seems to be problem as the program does not know when it is reading the last loop!!

How to resolve this??
 
Hi Zeth, Try this, this should terminate correctly for the last case.

%macro fre_pdf()/PARMBUFF;

ods listing close;
ods pdf file="C:\FREQ.pdf";
options nobyline nodate;

%* Strip off brackets from syspbuff;
%let y=%qsysfunc(compress(&syspbuff,'()'));
%let i=1;
%do %until (%qscan(%bquote(&y), &i, %str(,)) eq );
%* Extract arguments between commas and assign to variable x;
%let x=%qscan(%bquote(&y), &i, %str(,));
proc freq data=one_hundred;
tables &x / chisq;
title "&x";
run;
%let i=%eval(&i+1);
%end;

ods pdf close;
ods pdf(id=d3dstyle) close;

%mend fre_pdf;


%fre_pdf(a * a,c * d,e * f,g * h,l * m,n * o)
 
Thanks kdt82,

Next, i do the same procedure but in the macro i do a box_plot.

So i have to do a sort on the second variable.

proc sort data = all;
by &x;
run;

how to extract the second word and still loop??
 
If I understand you properly, then try the following. The macro scan function mirrors the normal data step function.

Just using scan to return the second part of the substring

Code:
%macro fre_pdf()/PARMBUFF;

ods listing close;
ods pdf file="C:\FREQ.pdf"; 
options nobyline nodate;

%* Strip off brackets from syspbuff;
%let y=%qsysfunc(compress(&syspbuff,'()'));
%let i=1;
%do %until (%qscan(%bquote(&y), &i, %str(,)) eq );
%* Extract arguments between commas and assign to variable x;
    %let x=%qscan(%bquote(&y), &i, %str(,));
          proc freq data=one_hundred;
              tables &x / chisq;
              title "&x";
          run;

    %let z=%scan(&x,2,*);
          proc sort data = all;
              by &z;
          run;

    %let i=%eval(&i+1);
%end;

ods pdf close;
ods pdf(id=d3dstyle) close;

%mend fre_pdf;

%fre_pdf(a * a,c * d,e * f,g * h,l * m,n * o)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top