02-01-2016 10:12 AM
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 = );
create table stat (_TYPE_ num,
proc sql noprint;
select count(pcm_var) into: pcmvar_cnt
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 ;
length pcmvar $30. ;
pcmvar= "%scan(&pcmvar., &i. )";
data stat ;
set stat stat_i;
proc datasets library = work ;
delete summary_&i. stat_&i. ;
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_range_&cohort.= "Median (Min, Max)"
pcm_n_&cohort. = "N"
ps_n_&cohort. = "N";
02-01-2016 10:22 AM
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.
02-01-2016 10:22 AM
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.
02-01-2016 10:40 AM
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.
02-01-2016 02:10 PM
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.