BookmarkSubscribeRSS Feed
cws
Fluorite | Level 6 cws
Fluorite | Level 6
Does anyone know why my class variable TREAT (numeric) gets switched to character in ODS table LSMEANS? It doesn't happen in LSMEANDIFFCL, so if you want to merge the two datasets for printing a report it means you have to convert it as one dataset has TREAT as a character variable and the other has it as numeric. I am sure this didn't happen in 9.1.
7 REPLIES 7
data_null__
Jade | Level 19
I have 9.1.3. In that version LSMeanDiffCL does not have the variable named in the LSMEANS statement. It has I and J and they relate to LSMeanNumber in the LSMEANS data set. Are you referring to ODS output data set LSMEANCL which does NOT have LSMeanNumber but is very similar to LSMEANS?

Merge LSMEANS with LSMEANSCL to get LSMeanNumber and you should be able to relate that to I J in LSMeanDiffCL.

[pre]
data test;
do rep=1 to 3;
do trt = 1 to 3;
y = ranuni(454545);
output;
end;
end;
run;
proc print;
run;
ods trace on;
proc glm;
class trt;
model y = trt;
lsmeans trt / cl pdiff;
ods output LSMeans=LSMeans LSMeanDiffCL=LSMeanDiffCL LSMeanCL=LSMeanCL;
run;
ods trace off;
proc contents varnum data=LSMeans;
ods select Position;
run;
proc print data=LSMeans;
run;
proc contents varnum data=LSMeanCL;
ods select Position;
run;
proc print data=LSMeanCL;
run;
proc contents varnum data=LSMeanDiffCL;
ods select Position;
run;
proc print data=LSMeanDiffCL;
run;
[/pre]

With output....

[pre]
The SAS System 117
06:16 Monday, March 15, 2010

The CONTENTS Procedure

Variables in Creation Order

# Variable Type Len Format Label

1 Effect Char 9
2 Dependent Char 8
3 trt Char 1
4 LSMean Num 8 12.8 y LSMEAN
5 LSMeanNumber Num 8 BEST8. LSMEAN Number

The SAS System 118
06:16 Monday, March 15, 2010

LSMean
Obs Effect Dependent trt LSMean Number

1 trt y 1 0.54560722 1
2 trt y 2 0.87772021 2
3 trt y 3 0.31259905 3

The SAS System 119
06:16 Monday, March 15, 2010

The CONTENTS Procedure

Variables in Creation Order

# Variable Type Len Format Label

1 Effect Char 9
2 Dependent Char 8
3 trt Char 1
4 LowerCL Num 8 D12.3
5 LSMean Num 8 D12.3 y LSMEAN
6 UpperCL Num 8 D12.3

The SAS System 120
06:16 Monday, March 15, 2010

Obs Effect Dependent trt LowerCL LSMean UpperCL

1 trt y 1 0.243535 0.545607 0.847680
2 trt y 2 0.575648 0.877720 1.179793
3 trt y 3 0.010527 0.312599 0.614671

The SAS System 121
06:16 Monday, March 15, 2010

The CONTENTS Procedure

Variables in Creation Order

# Variable Type Len Format Label

1 Effect Char 9
2 Dependent Char 8
3 i Num 8 1.
4 j Num 8 1.
5 LowerCL Num 8 D12.3
6 Difference Num 8 D12.3 Difference Between Means
7 UpperCL Num 8 D12.3

The SAS System 122
06:16 Monday, March 15, 2010

Obs Effect Dependent i j LowerCL Difference UpperCL

1 trt y 1 2 -0.759308 -0.332113 0.095082
2 trt y 1 3 -0.194187 0.233008 0.660203
3 trt y 2 3 0.137926 0.565121 0.992316
[/pre]
cws
Fluorite | Level 6 cws
Fluorite | Level 6
Thanks data null. I am using the PDIFF=CONTROL option in 9.2, which compares each treatment to a control, so the values of TRT should match between the two datasets.
proc glm data=test;
class trt;
model y = trt;
lsmeans trt / cl pdiff=control('3');
ods output LSMeans=LSMeans LSMeanDiffCL=LSMeanDiffCL LSMeanCL=LSMeanCL;
run;


However, if you note the type of the variable TRT, you will see they are different:

LSMeans dataset
NB type of variable TRT

The CONTENTS Procedure

Variables in Creation Order

# Variable Type Len Format Label

1 Effect Char 9
2 Dependent Char 8
3 trt Char 1
4 LSMean Num 8 12.8 y LSMEAN
5 LSMeanNumber Num 8 BEST8. LSMEAN Number


LSMeanCL dataset
NB type of variable TRT

The CONTENTS Procedure

Variables in Creation Order

# Variable Type Len Format Label

1 Effect Char 9
2 Dependent Char 8
3 trt Char 1
4 LowerCL Num 8 D12.3
5 LSMean Num 8 D12.3 y LSMEAN
6 UpperCL Num 8 D12.3

LSMEANDIFFCL dataset

NB type of variable TRT

The CONTENTS Procedure

Variables in Creation Order

# Variable Type Len Format Label

1 Effect Char 9
2 Dependent Char 8
3 i Num 8 1.
4 j Num 8 1.
5 LowerCL Num 8 D12.3
6 Difference Num 8 D12.3 Difference Between Means
7 UpperCL Num 8 D12.3
8 trt Num 8
9 _trt Num 8

For some reason TRT goes from being numeric (in LSMEANDIFFCL) to character in LSMEANS and LSMEANCL.
data_null__
Jade | Level 19
Interesting with 9.1.3 I don't get trt and _trt., even when I add CONTROL, as you did. Delete: (You still have I, J and LSMEANNUMBER so no problem.)

I was not looking closely enough. I now see that with CONTROL the LSMEANS ODS data set does NOT include lsmean number. That is a bit of a pickle. You could read the character treatment values to create a numeric value or use another LSMEANS statement to get an LSMEANS data set with LSMeanNnumber.

I guess the "best" thing to do is use character TRT.

It is frustrating.

[pre]
# Variable Type Len Format Label

1 Effect Char 9
2 Dependent Char 8
3 i Num 8 1.
4 j Num 8 1.
5 LowerCL Num 8 D12.3
6 Difference Num 8 D12.3 Difference Between Means
7 UpperCL Num 8 D12.3
[/pre] Message was edited by: data _null_;
cws
Fluorite | Level 6 cws
Fluorite | Level 6
Hi
Well it is still a problem because there is nothing to merge with: LSMEANS (or LSMEANCL) does not have i and j in them. LSMEANDIFFCL has everything (i,j,TRT etc). In order to merge you need to create another dataset from LSMEANS, converting TRT into a numeric variable TRTN (or similar) then merge back in, renaming TRTN back to TRT. Very tedious! Or is there another way I can combine the means, differences from control, CIs for output by a PROC REPORT. I can't think of another way. I may be forced to use ESTIMATE I guess.
data_null__
Jade | Level 19
I'm not sure exactly which data you want to combine. And what the result should be. If you could be specific and show example that would be helpful. Use the have/need scenario.

The simplest would be to convert TRT to character first.

There is OUT= on LSMEANS statement which preserves the type for TRT.

This is also PROC MIXED, which I'm pretty sure does not have these "issues".
cws
Fluorite | Level 6 cws
Fluorite | Level 6
That's a helpful suggestion using the OUT= option in LSMEANS. It still seems odd to me that the type of the class variable should change in ODS output: do you suppose it is a bug or is it meant to happen?

What I am trying to achieve is a table:
Treatment Mean Diff from control 95% CI for diff
Control xxx - -
Treat 1 xxx yyy zz to zz
Treat 2 xxx yyy zz to zz
Treat 3 xxx yyy zz to zz
data_null__
Jade | Level 19
I don't think it is a bug. ODS OUTPUT is very different from Output data sets. The ODS data set are display dependent, (my term) which can be frustrating.

For your data I would create I on LSMEANS and merge with LSMEANDIFFCL by I.
You may have a more complex problem: more effects more Ys but I think the technique can be adapdted to that too.

[pre]
data test;
do rep=1 to 3;
do trt = 0 to 4;
y = ranuni(454545);
output;
end;
end;
run;
proc print;
run;
*ods trace on;
proc glm;
class trt;
model y = trt;
lsmeans trt / cl pdiff=control('0');
ods output LSMeans=LSMeans LSMeanDiffCL=LSMeanDiffCL;
run;
run;
ods trace off;

/*
What I am trying to achieve is a table:
Treatment Mean Diff from control 95% CI for diff
Control xxx - -
Treat 1 xxx yyy zz to zz
Treat 2 xxx yyy zz to zz
Treat 3 xxx yyy zz to zz
*/
data lsmeans;
set lsmeans;
by effect;
if first.effect then i = 0;
i + 1;
run;
proc print data=LSMeanCL;
run;

data combined;
merge lsmeans lsmeandiffcl;
by effect i;
run;
proc print;
run;
[/pre]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 5241 views
  • 0 likes
  • 2 in conversation