I am running a model using proc genmod and have run a lsmeans statement. I would like to save only some of the columns of the lsmeans table using the ods output.
General setup:
proc genmod data = data; class x; model y= x / dist = nb link = log offset = myoff; lsmeans x / pdiff; ods output 'x Diffs'=diffs(keep = x Estimate 'Standard Error'); run;
This gives the error that 'Standard Error' is not valid. This is not surprising because it has a space in the variable name.
I tried specifying as:
ods output 'x Diffs'=diffs(keep = x Estimate 'Standard Error'n);
which adds the 'n' as suggested here but that also does not work. There are many variable names in output tables which contain spaces, so understanding how to do this would be very helpful. Thank you
Are you sure such a variable exists? Run it without the KEEP= and run a PROC CONTENTS on the resulting dataset.
Are you sure that is the right name for the ODS output you want saved to a dataset?
What do you see when you turn on ODS TRACE and run the PROC without the ODS OUTPUT statement?
Are you sure such a variable exists? Run it without the KEEP= and run a PROC CONTENTS on the resulting dataset.
Are you sure that is the right name for the ODS output you want saved to a dataset?
What do you see when you turn on ODS TRACE and run the PROC without the ODS OUTPUT statement?
Yes, I see now that what I was trying to use were the labels. All the variable names are created to have no spaces (e.g., StdErr) and can be kept in the keep line easily.
I strongly suspect that you are seeing variable labels that you think are variable names.
Run proc contents on your data set to confirm actual variable names and/or labels.
I will also place a small wager that you have a warning similar to this in your log.
WARNING: Output ''x diffs'' was not created. Make sure that the output object name, label, or path is spelled correctly. Also, verify that the appropriate procedure options are used to produce the requested output object. For example, verify that the NOPRINT option is not used.
The syntax for the ODS output is
ods output <source data>= the_name_of_your_dataset;
And the the oppropriate source data set would be DIFFS, not "x diffs". And if the name had actually been "x diffs" that would require the use of another name literal
And I suspect that you actually want the Ods output lsmeans=somedataset; which will have
Alphabetic List of Variables and Attributes # Variable Type Len Format Label 2 Effect Char 3 4 Estimate Num 8 D8.4 7 Probz Num 8 PVALUE6.4 Pr > |z| 5 StdErr Num 8 D8.4 Standard Error 1 StmtNo Num 8 BEST4. Statement Number 3 mfg Char 1 6 zValue Num 8 7.2 z Value
Where you can see the label is "Standard Error" for the variable StdErr.
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.