We find that different SAS users obtain different results when running identical PROC GLM code on our system. (SAS 9.4 TS Level 1M4; Windows Version 6.3.9600)
A typical example is
ods output LSMeans = LSMeans1; proc glm data=temp; class trtseqpn subjid aperiod trta; model aval = trta trtseqpn aperiod subjid(trtseqpn) /ss3; random subjid(trtseqpn) / test; estimate "Estimate1" trta 1 -1 ; lsmeans trta ; run; quit;
The resulting ODS dataset "LSMeans1" is slightly different for different users. For some, the least squares mean will appear in a variable called "LSMean"; for others, the variable name will be "avalLSMean." (Note that "aval" comes from the name of the dependent model variable). Naturally this can cause errors later in the program if the variable name is not as expected.
Is there something we can do to ensure a consistent result? (I can write macro code to rename the variable conditionally, but would prefer a simpler solution.)
The structure of the input data is straightforward, e.g.
data WORK.TEMP; input subjid $ aperiod trta $ trtseqpn aval; datalines; 1 1 A 1 1.23456 1 2 B 1 2.13632 2 1 B 2 0.54719 2 2 A 2 0.89158 [...] ;
I think I have discovered the answer: It appears that if you use ODS graphics that the variables in the LSMeans table can change names, as you report:
data A;
set sashelp.class;
run;
%macro body();
class sex;
model Height = sex /ss3;
lsmeans sex;
%mend;
ods exclude all;
ods select LSMeans;
proc glm data=A PLOTS=NONE;
%body;
ods output LSMeans = LSMeans1;
run; quit;
ods exclude none;
proc contents data=LSMeans1 varnum short; run;
ods exclude all;
ods select LSMeans;
proc glm data=A PLOTS(only)=MeanPlot;
%body;
ods output LSMeans = LSMeans2;
run; quit;
ods exclude none;
proc contents data=LSMeans2 varnum short; run;
Thank you for your response.
We ran the code you supplied and verified the resulting log output is the same. Actually, there is only one copy of SAS being used, so there isn't much room for discrepancies of this sort.
I should note that at least some of the affected users are in different regions. Some SAS behavior is region-specific (for instance, the paper size for printed output defaults to 8.5"x11" for US users and A4 for many others) though I would not expect this to be such a case.
The only other time I've seen this is when some use EG, some use Base/Studio.
If you're all using the exact same input and software versions, then I think you should raise this with SAS Tech Support.
Compare the setting of VALIDVARNAME for users getting different results.
Perhaps the one of the users has modified the template uses to create LSMEANS output.
We both have VALIDVARNAME=V7 (good idea, though!) and are both running simply SAS, not EG/Studio.
Thanks for your help; we'll contact technical support.
You didn't say if you look to see if one of the users had modified the template.
@rmcneive wrote:
We both have VALIDVARNAME=V7 (good idea, though!) and are both running simply SAS, not EG/Studio.
Thanks for your help; we'll contact technical support.
Sorry for the omission: the answer to this was also no.
"aval LSMean" (with a space) will be the LABEL associated with that variable, as you can see by running
proc template;
source stat.GLM.LSMeans;
run;
If some users are using
PROC PRINT data=LSMeans1; run;
whereas others are showing the labels as
PROC PRINT data=LSMeans1 LABEL; run;
then some will see the label and others will see the variable name.
I don't think there is a way to use the labels as the variable name in a SAS data set, but if you are using PROC EXPORT to write the data to an Excel file, you can do it by using the LABEL op.... Are these "variable names" coming from some data that you exported?
In short, I think some of your analysts are seeing the label, not the variable name. If you run
PROC CONTENTS data=LSMeans1 short varnum; run;
you should see the TRUE variable names.
Thanks for your reply. Unfortunately the answer is not that simple: it is actually the variable name which differs, and not the label. In subsequent DATA steps, some users must insert code such as
RENAME avalLSMean = LSMean;
or else they will get errors like "Variable LSMean is not initialized." Other users, when running an identical program in a fresh SAS session, must omit this statement to avoid errors.
Can you post the results of
PROC CONTENTS data=LSMeans1 varnum; run;
for one of the users who observes 'avalLSMeans'?
Certainly; please see below.
The CONTENTS Procedure Data Set Name WORK.LSMEANS1 Observations 24 Member Type DATA Variables 8 Engine V9 Indexes 0 Created 09/27/2018 13:41:47 Observation Length 48 Last Modified 09/27/2018 13:41:47 Deleted Observations 0 Protection Compressed NO Data Set Type Sorted NO Label Data Representation WINDOWS_64 Encoding wlatin1 Western (Windows) Engine/Host Dependent Information Data Set Page Size 65536 Number of Data Set Pages 1 First Data Page 1 Max Obs per Page 1361 Obs in First Data Page 24 Number of Data Set Repairs 0 ExtendObsCounter YES Filename D:\sastemp\_TD18204_PGHSAS2_\lsmeans1.sas7bdat Release Created 9.0401M4 Host Created X64_SR12R2 Owner Name NOVUM\RM1132 File Size 128KB File Size (bytes) 131072 The CONTENTS Procedure Variables in Creation Order # Variable Type Len Format Label 1 PARAMCD Char 8 $PAR. PK PARAMETER 2 Effect Char 16 3 TRTA Char 1 4 avalLSMean Num 8 12.8 aval LSMEAN 5 APERIOD Char 1 6 TRTSEQPN Char 1 7 compnum Num 8 8 comp Char 3
A quick addendum: you may notice the "compnum" and "comp" variables. These were added in a subsequent DATA step. As per the log data shown below, there are no other changes:
MPRINT(BEMODEL_PAIR): data LSMeans1 ; MPRINT(BEMODEL_PAIR): set LSMeans1; MPRINT(BEMODEL_PAIR): compnum=1 ; MPRINT(BEMODEL_PAIR): comp="A-B" ; MPRINT(BEMODEL_PAIR): run;
Quick confirmation, the GLM code in your initial post is exactly what each person is running?
I think I have discovered the answer: It appears that if you use ODS graphics that the variables in the LSMeans table can change names, as you report:
data A;
set sashelp.class;
run;
%macro body();
class sex;
model Height = sex /ss3;
lsmeans sex;
%mend;
ods exclude all;
ods select LSMeans;
proc glm data=A PLOTS=NONE;
%body;
ods output LSMeans = LSMeans1;
run; quit;
ods exclude none;
proc contents data=LSMeans1 varnum short; run;
ods exclude all;
ods select LSMeans;
proc glm data=A PLOTS(only)=MeanPlot;
%body;
ods output LSMeans = LSMeans2;
run; quit;
ods exclude none;
proc contents data=LSMeans2 varnum short; run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.