When I ran this macro, I got two errors:
Open code statement recursion detected.
ERROR: Macro keyword MEND appears as text. A semicolon or other delimiter may be missing.
what causes these two errors? Thanks.
%macro stat(paramcd=,aval=,m=,n=);
proc univariate data=adptdc noprint;
by arm;
var &aval;
where paramcd=¶mcd; /*paramcd='TFMT2RD';*/
output out=TFMT2RD n=n mean=mean std=sd median=median min=min max=max q1=q1 q3=q3;
run;
proc format;
value stat
1='n'
2='Mean (SD)'
3='Median'
4='Q1 - Q3'
5='(Min-Max)';
run;
data TFMT2RD_;
set TFMT2RD;
length stat_ $ 10 col $ 20;
stat=1; stat_ = trim(left(put(stat, stat.))); col = put(n,3.); output;
stat=2; stat_ = trim(left(put(stat, stat.))); col = put(mean,5.1)||' ('||put(sd,5.2)||')'; output;
stat=3; stat_ = trim(left(put(stat, stat.))); col = put(q1,5.1)||' - '||strip(put(q3,5.1)); output;
stat=4; stat_ = trim(left(put(stat, stat.))); col = put(median,5.1); output;
stat=5; stat_ = trim(left(put(stat, stat.))); col = '('||put(min,5.1)||' - '||strip(put(max,5.1))||')'; output;
keep arm stat stat_ col;
run;
proc sort data=TFMT2RD_; by stat stat_;run;
proc transpose data=TFMT2RD_ out=mean_TFMT2RD (srop=_name_);
by stat stat_;
var col;
id arm;
run;
***Unstratified P-value;
proc npar1way wilcoxon data=adptdc_1;
class arm;
var &aval;
where paramcd=¶mcd; /*paramcd='TFMT2RD';*/
output out = pvalue wilcoxon;
run;
data pvalue_;
set pvalue;
stat=6;
stat_="Unstr P";
LU_177_OCTREOTATE=put(P2_WIL,6.4);
keep stat stat_ LU_177_OCTREOTATE;
run;
* stratefy OCTDOSTR & OCTUPTSR;
data stratefy;
merge adptdc_1 (in=a) adam.adsl(keep=usubjid arm OCTDOSTR OCTUPTSR);
by usubjid;
if a;
if paramcd=¶mcd; /*paramcd='TFMT2RD';*/
run;
Proc freq data=stratefy noprint;
table OCTDOSTR * OCTUPTSR *arm * &aval / score=modridit cmh;
output out = pvalue_cmh cmh;
Run;
data pvalue_cmh_;
set pvalue_cmh;
stat=7;
stat_="Stra P";
LU_177_OCTREOTATE=put(P_CMHCOR,6.4);
keep stat stat_ LU_177_OCTREOTATE;
run;
data stat_&m_&n;
set mean_TFMT2RD pvalue_ pvalue_cmh_;
run;
%mend stat;
%stat(paramcd='TFDG2RD',aval=months,m=1,n=1);
%stat(paramcd='TFDG2RD',aval=years,m=1,n=2);
@fengyuwuzu Run it with macro debugging options on and post the log.
There is a typo in your PROC TRANSPOSE statement - DROP not SROP.
When passing values that are to be quoted, it is much safer to do the quoting in the code instead of in the parameter. For instance the WHERE becomes:
where paramcd="¶mcd";
This allows the macro call to become:
%stat(paramcd=TFDG2RD,aval=months,m=1,n=1);
Because of the way that quoted strings are parsed, this can make a difference.
At the very end, you are missing a dot:
data stat_&m._&n;
Without it, SAS doesn't know if the name of the macro variable should be &M or &M_
A good example of why always putting dots at the end of macro variables should be good programming practice (and it highlights macro variables in your code in the enhanced editor also).
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.