Hi All,
I'm trying to append proc means table for 40 variables. And I used below macro code to do so. Whenever I run this code it reads me an error "WARNING: Variable Mean was not found on BASE file. The variable will not be added to the BASE file." And the table age_table contains only one variable that is gender. Can please anybody help.
Thanks,
Esita
%macro avg (group);
proc means data=clinic.diabetes;
var age ;
class gender;
output out=avg_age;
run;
data avg_age;
length gender $ 7;
set avg_age;
gender="&group";
run;
proc append base=age_table
data=avg_age
force;
run;
%mend avg;
%avg(male_diabetes);
%avg(male_hypertension);
%avg(female_diabetes);
%avg(female_hypertension);
Why are you trying to do this?
I am trying to work out why this is necessary.
Since the group macro variable isn't used in your proc means I'm not sure your code is actually doing what you want it to do.
Perhaps post what you have and what you need instead?
Reeza, My apologies for not having clear code. Actually I was trying to write a shorter code for the similar problem I was having with my SAS code so I might have messed it up. So, This is my code. I'm trying to append all the estimate_table for all var (WBC, neutro....I have 40 of them). So I created a new data all_estimate ( base) and appended all the estimate_tables to it. But, SAS reads me an error saying
WARNING: Variable Label was not found on BASE file. The variable will not be added to the BASE
file.
WARNING: Variable Estimate was not found on BASE file. The variable will not be added to the BASE
file.
WARNING: Variable StdErr was not found on BASE file. The variable will not be added to the BASE
file.
WARNING: Variable DF was not found on BASE file. The variable will not be added to the BASE file.
WARNING: Variable tValue was not found on BASE file. The variable will not be added to the BASE
file.
WARNING: Variable Probt was not found on BASE file. The variable will not be added to the BASE
file.
I wanted my output like this
Variable | label | estimate | stdErr | DF | tValue | Probt |
wbc | time1vstime0 | 0.007 | 1.19 | 79 | 1.78 | 0.063 |
wbc | time2vstime0 | 2.1 | 2.06 | 79 | 1.02 | 0.313 |
wbc | time3vstime0 | 2.24 | 2.09 | 79 | 1.5 | 0.28 |
neutro | time1vstime0 | 0.018 | 1.169 | 79 | 1.98 | 0.093 |
neutro | time2vstime0 | 2.1 | 2.06 | 79 | 1.02 | 0.313 |
neutro | time3vstime0 | 2.24 | 2.09 | 79 | 1.5 | 0.28 |
BUT my output table all_estimate contatins only variable list..
Variable |
wbc |
wbc |
wbc |
neutro |
neutro |
neutro |
%macro diabetes (var);
proc mixed data=diabetes ;
class time status patient ;
model &var = time|status;
repeated time / type=SP(pow)(day) subject=patient;
lsmeans time|status ;
estimate 'time1vstime0' time -1 1 0 0;
estimate 'time2vstime0' time -1 0 1 0;
estimate 'time3vstime0' time -1 0 0 1;
ods output estimates=estimate_table;
run;
data estimate_table;
length Variable $ 20;
set estimate_table;
Variable="&var";
run;
proc append base=all_estimate
data=estimate_table
force;
run;
%mend diabetes;
%diabetes(WBC);
%diabetes(Neutro);
I don't see anything wrong with your code, but I'm not too familiar with proc mixed.
Run the macro once and verify that the estimate table is being generated properly.
Also, manually delete the all_estimate table as any bad runs may have messed things up.
How about you rename the dataset from ESTIMATE_TABLE to ALL_ESTIMATE on the first run by identifying that ALL_ESTIMATE does not exist. This will give you the backbone for future PROC APPENDS. Something like the below, however this is untested so you might have to make a few changes.
PROC DATASETS LIBRARY = WORK;
delete ESTIMATE_TABLE;
RUN;
%macro diabetes (var);
proc mixed data=diabetes ;
class time status patient ;
model &var = time|status;
repeated time / type=SP(pow)(day) subject=patient;
lsmeans time|status ;
estimate 'time1vstime0' time -1 1 0 0;
estimate 'time2vstime0' time -1 0 1 0;
estimate 'time3vstime0' time -1 0 0 1;
ods output estimates=estimate_table;
run;
data estimate_table;
length Variable $ 20;
set estimate_table;
Variable="&var";
run;
%IF EXIST(ALL_ESTIMATE) = 0 %THEN %DO;
PROC DATASETS LIBRARY = WORK;
CHANGE ESTIMATE_TABLE = ALL_ESTIMATE;
RUN;
%END;
%ELSE %DO;
PROC APPEND BASE=ALL_ESTIMATE DATA=ESTIMATE_TABLE;
RUN;
%END;
%mend diabetes;
%diabetes(WBC);
%diabetes(Neutro);
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.