DATA Step, Macro, Functions and more

ERROR: Macro keyword MACRO appears as text. A semicolon or other delimiter may be missing.

Reply
Frequent Contributor
Frequent Contributor
Posts: 76

ERROR: Macro keyword MACRO appears as text. A semicolon or other delimiter may be missing.

Dear all,

 

My following macro did not run for the reasons :

ERROR: Macro keyword MACRO appears as text. A semicolon or other delimiter may be missing.

ERROR: Macro keyword DO appears as text. A semicolon or other delimiter may be missing.

ERROR: Macro keyword IF appears as text. A semicolon or other delimiter may be missing.

....

 

May you let me know what I missed in the macros ?  Thank you very much.  Ivy 

 

%macro ps_summary (inds = , outds= , cohort = );

proc sql;
create table stat (_TYPE_ num,
_FREQ_ num,
psmean num,
pcmmean num,
psstd num,
pcmstd num,
psmed num,
pcmmed num,
psmin num,
pcmmin num,
psmax num,
pcmmax num,
pcmvar num);
quit;

proc sql noprint;
select count(pcm_var) into: pcmvar_cnt
from ads.pcm_names
where index(pcm_var, "CCMD" ) > 0 or index(pcm_var, "score") > 0 or index(pcm_var, "CCMA") > 0 ;
quit;


%do i = 1 %to &pcmvar_cnt.;

proc means data = &inds. ;
var performance_value %scan(&pcmvar., &i. );
where %scan(&pcmvar., &i. ) ^= . ;
output out = summary_&i. mean = psmean pcmmean std = psstd pcmstd median = psmed pcmmed min= psmin pcmmin max = psmax pcmmax ;
run;

%if %sysfunc(exist(summary_&i.) %then %do ;

data stat_&i.;
set summary;
length pcmvar $30. ;
pcmvar= "%scan(&pcmvar., &i. )";
run;

data stat ;
set stat stat_i;
run;

proc datasets library = work ;
delete summary_&i. stat_&i. ;
run;
quit;

%end;

%end;

 

data &outds.;
set stat;
pcm_mean_sd_&cohort. = cat(put(pcmmean,5.2)," (",put(pcmstd,5.2),")");
pcm_range_&cohort. = cat(put(pcmmed,5.2)," (",put(pcmmin,5.2),",",put(pcmmax,5.2),")");
ps_mean_sd_&cohort. = cat(put(psmean,5.2)," (",put(psstd,5.2),")");
ps_range_&cohort. = cat(put(psmed,5.2)," (",put(psmin,5.2),",",put(psmax,5.2),")");
pcm_n_&cohort. = _freq_;
ps_n_&cohort. = _freq_;
label pcm_mean_sd_&cohort. = "Mean (SD)"
pcm_range_&cohort.= "Median (Min, Max)"
ps_mean_sd_&cohort.="Mean (SD)"
ps_range_&cohort.= "Median (Min, Max)"
pcm_n_&cohort. = "N"
ps_n_&cohort. = "N";
run;

%mend;

 

Super User
Super User
Posts: 6,495

Re: ERROR: Macro keyword MACRO appears as text. A semicolon or other delimiter may be missing.

You need to look for the cause in the code submitted before the lines you sent.  You must have missing semi-colon or unbalanced quotes or brackets that caused %MACRO to not be processed. The other errors should go away once you fix that.  You might just need to close SAS and start over.

Contributor
Posts: 38

Re: ERROR: Macro keyword MACRO appears as text. A semicolon or other delimiter may be missing.

It looks like there are some missing semi-colons near the bottom. But, I'm wondering if you have custom code that is being inserted before a job submission. Or, if you have any other code before what you've shared here.

Super User
Super User
Posts: 7,392

Re: ERROR: Macro keyword MACRO appears as text. A semicolon or other delimiter may be missing.

I am not sure why the need for all that code?  Simply normalise your data - long dataset rather than wide dataset - and put a by statement in your proc means.  Then transpose up the resulting data as you want in a datastep.  No need for macro's, macro looping, create datasets code, delete temporaries etc.  Far cleaner.  If you post some test data in the form of a datastep, and what you want the output to look like I can provide some code.

Frequent Contributor
Frequent Contributor
Posts: 76

Re: ERROR: Macro keyword MACRO appears as text. A semicolon or other delimiter may be missing.

Thank you very much, all.

 

Found the problems, when I create the empty dataset,  I should use char. for one variable, however, I treated it as numeric variable.

 

 

Ask a Question
Discussion stats
  • 4 replies
  • 1727 views
  • 2 likes
  • 4 in conversation