BookmarkSubscribeRSS Feed
Quartz | Level 8 Ivy
Quartz | Level 8

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

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 ;

%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 ;

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

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

data stat ;
set stat stat_i;

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




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";



Super User Tom
Super User

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.

Obsidian | Level 7

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.

Diamond | Level 26 RW9
Diamond | Level 26

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.

Quartz | Level 8 Ivy
Quartz | Level 8

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.



Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 in conversation