%Macro orderstats(var=Total_Retail_Price, class=Customer_ID, stats=mean,
decimals=2);
options nolabel;
title 'Order Stats';
proc means data=mc1.orders maxdec=&decimals &stats;
var &var;
class &class;
run;
title;
options label;
%mend Orderstats;
%orderstats()
Hi,
Are you sure the input data set exists / is spelled correctly and are the variable names correct?
Please add the following statement to the start of the code for diagnostics and then run the code again:
options mprint;
Then please share the log using the Insert Code icon "</>".
I've tried replicating the code by copying data set sashelp.class and using that in your macro:
data orders;
set sashelp.class(rename=(Age = Total_Retail_Price name = Customer_ID));
run;
options mprint;
%Macro orderstats(var=Total_Retail_Price, class=Customer_ID, stats=mean,
decimals=2);
options nolabel;
title 'Order Stats';
proc means data=orders maxdec=&decimals &stats;
var &var;
class &class;
run;
title;
options label;
%mend Orderstats;
%orderstats()
This gives me:
My log shows:
72 data orders; 73 set sashelp.class(rename=(Age = Total_Retail_Price name = Customer_ID)); 74 run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.ORDERS has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 833.09k OS Memory 23204.00k Timestamp 02/02/2025 02:43:20 PM Step Count 38 Switch Count 2 Page Faults 0 Page Reclaims 150 Page Swaps 0 Voluntary Context Switches 10 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 264 75 76 77 options mprint; 78 79 80 %Macro orderstats(var=Total_Retail_Price, class=Customer_ID, stats=mean, 81 decimals=2); 82 options nolabel; 83 84 title 'Order Stats'; 85 86 proc means data=orders maxdec=&decimals &stats; 87 var &var; 88 class &class; 89 run; 90 91 title; 92 options label; 93 %mend Orderstats; 94 95 %orderstats() MPRINT(ORDERSTATS): options nolabel; MPRINT(ORDERSTATS): title 'Order Stats'; MPRINT(ORDERSTATS): proc means data=orders maxdec=2 mean; MPRINT(ORDERSTATS): var Total_Retail_Price; MPRINT(ORDERSTATS): class Customer_ID; MPRINT(ORDERSTATS): run; NOTE: There were 19 observations read from the data set WORK.ORDERS. NOTE: PROCEDURE MEANS used (Total process time): real time 0.03 seconds user cpu time 0.03 seconds system cpu time 0.01 seconds memory 10110.90k OS Memory 33208.00k Timestamp 02/02/2025 02:43:20 PM Step Count 39 Switch Count 1 Page Faults 0 Page Reclaims 2408 Page Swaps 0 Voluntary Context Switches 12 Involuntary Context Switches 1 Block Input Operations 0 Block Output Operations 8 MPRINT(ORDERSTATS): title; MPRINT(ORDERSTATS): options label; 96
Thanks & kind regards,
Amir.
Are you sure the macro is being invoked and the Proc MEANS is run?
During code development you can sometimes have an unclosed string or parenthetical expression, which will cause the most recent 'Run' or 'Submit' to have Log lines that humans see as nothing was done.
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.
Ready to level-up your skills? Choose your own adventure.