BookmarkSubscribeRSS Feed
fengyuwuzu
Pyrite | Level 9

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=&paramcd; /*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=&paramcd; /*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=&paramcd; /*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);
4 REPLIES 4
Reeza
Super User

@fengyuwuzu Run it with macro debugging options on and post the log. 

ArtC
Rhodochrosite | Level 12

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="&paramcd";

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.

Astounding
PROC Star

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_

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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).

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 6358 views
  • 1 like
  • 5 in conversation