BookmarkSubscribeRSS Feed
esita
Calcite | Level 5

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

5 REPLIES 5
Scott_Mitchell
Quartz | Level 8

Why are you trying to do this?

I am trying to work out why this is necessary.

Reeza
Super User

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?

esita
Calcite | Level 5

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

VariablelabelestimatestdErrDFtValueProbt
wbctime1vstime00.0071.19791.780.063
wbctime2vstime02.12.06791.020.313
wbctime3vstime02.242.09791.50.28
neutrotime1vstime00.0181.169791.980.093
neutrotime2vstime02.12.06791.020.313
neutrotime3vstime02.242.09791.50.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);

Reeza
Super User

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.

Scott_Mitchell
Quartz | Level 8

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1883 views
  • 0 likes
  • 3 in conversation