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!

some questions on how to use macro?

Status
Not open for further replies.

charisi

Technical User
May 25, 2009
9
AU
klaz2002 (Programmer)
3 Jun 09 12:10
probably data steps.

Thank klaz2002
for this valuable post!


Inappropriate post?
If so, Red Flag it!


Check out the FAQ
area for this forum!

charisi (TechnicalUser)
7 Jun 09 20:45
i have a data set and would like to run macro and obtain summary statistics for three numeric variables var2,var3,var4 against one categoric variable(var5) using
the following either of this code:

%macro examq1f(id, var2, var3, var4, var5);
proc freq;
title 'frequency tables using macro';
tables &table var &id &var2 &var3&var4 &var5;
run;
proc means n mean std median Q1 Q3 max min;
var &var2 &var3 &var4;
run;
proc sort;
by &var5;
run;
%mend examq1f;
%examq1f;
%examq1f;

or alternatively%macro examq1f(tablevar)
proc freq;
title frequency tables using a macro';
tables &tablevar;
%mend examq1f;
%examqif(var5);
%examq1f(var5);

iam failing to get an output or print out when i run this code.
what am i doing wrong klaz?
how can i get an output or print out using this macro code or is this the wrong way of running / using macro to obtain the summary statistics? how can one use macro in this scenario?
i have also tried to run; code:
options mprint mlogic symbolgen:
and still can not get macro running or give me an out put even using pro print; run;
can you please help ?
 
Your %examq1f macro doesn't have a RUN statement. Perhaps that's why it doesn't work. Also, you should use the DATA= option in the PROC statement. This way anyone reading your code can see what you're processing. If you want to see the results in a SAS dataset you can use the OUT= or OUTPUT and the OUT suboption (for PROC FREQ).

I hope that this helps you.
Klaz
 
%macro examq1f(id, nodes,prog_recp, estrg_recp, menopause);
run;
proc freq data = work.gbcsmerged;
output= title 'frequency tables using macro';
tables &table var &id &nodes &prog_recp &estrg_recp &menopause;
run;
proc means n mean std median Q1 Q3 max min;
var &nodes &prog_recp &estrg_recp;
run;
proc sort;
by &menopause;
run;
%amend examq1f;
run;
%examq1f;
%examq1f;
options mprint mlogic symbolgen;
run;
options mprint;
run;

my main dataset is gbcsmerged,and i want to perform macro on a few of the variables,nodes, prog receptors, estrg receptors by menopausal status ,after modifying this code to read as above i still get no SAS output is there something I am doing wrong?? the log window it reads like this: run;
407 proc contents data =work.gbcsmerged;
408 run;
409 proc sort data =work.gbcsmerged;
410 by id;
411 run;
412 proc contents data = work.gbcsmerged;
413 run;
414 %macro examq1f(id, nodes,prog_recp, estrg_recp, menopause);
415 run;
416 proc freq data = work.gbcsmerged;
417 output= title 'frequency tables using macro';
418 tables &table var &id &nodes &prog_recp &estrg_recp &menopause;
419 run;
420 proc means n mean std median Q1 Q3 max min;
421 var &nodes &prog_recp &estrg_recp;
422 run;
423 proc sort;
424 by &menopause;
425 run;
426 %amend examq1f;
427 run;
428 %examq1f;
429 %examq1f;
430 options mprint mlogic symbolgen;
431 run;
432 options mprint;
433 run;
but still no output can you help??
 
%macro examq1f(id, nodes,prog_recp, estrg_recp, menopause);
run;
proc freq data = work.gbcsmerged;
output= title 'frequency tables using macro';
tables &table var &id &nodes &prog_recp &estrg_recp &menopause;
run;
proc means n mean std median Q1 Q3 max min;
var &nodes &prog_recp &estrg_recp;
run;
proc sort;
by &menopause;
run;
%amend examq1f;
run;
%examq1f;
%examq1f;
options mprint mlogic symbolgen;
run;
options mprint;
run;

my main dataset is gbcsmerged,and i want to perform macro on a few of the variables,nodes, prog receptors, estrg receptors by menopausal status ,after modifying this code to read as above i still get no SAS output is there something I am doing wrong?? the log window it reads like this:

%macro examq1f(id, nodes,prog_recp, estrg_recp, menopause);
415 run;
416 proc freq data = work.gbcsmerged;
417 output= title 'frequency tables using macro';
418 tables &table var &id &nodes &prog_recp &estrg_recp &menopause;
419 run;
420 proc means n mean std median Q1 Q3 max min;
421 var &nodes &prog_recp &estrg_recp;
422 run;
423 proc sort;
424 by &menopause;
425 run;
426 %amend examq1f;
427 run;
428 %examq1f;
429 %examq1f;
430 options mprint mlogic symbolgen;
431 run;
432 options mprint;
433 run;
but still no output can you help??
 
Have you tried to run the PROC FREQ with out the macro wrapper?
Like this?
Code:
proc freq data = work.gbcsmerged;
      output= title 'frequency tables using macro';
      tables &table var &id &nodes &prog_recp &estrg_recp &menopause;
      run;

Of course change the macro variables to what they should be. If this works than you can troubleshoot the macro. Always make sure that the code can run. MACRO is only a fancy substitution of pure text before the SAS program executes. The rendered (substituted) SAS code must be able to run.

(The OUTPUT statement must have an 'OUT=datasetname' to it. I can't figure out where your '&Table' is set. Perhaps these are the errors?)

Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top