When using ODS Output I discovered that in SAS OnDemand some tables have variable names as numbers.
Previously in SAS Studio University Edition, those same variables would have had an underscore prefix. eg _1 _2
How am I to refer to these fields in a subsequent statement without getting an error?
Here is a simplified version of what I'm doing. I fit a GLM model and send the LSMeans Difference output to a table. I then try to refer to it but fail.
/* run the model and generate the ODS Output data */
proc glm data=TEST; class FactorA FactorB FactorC; model Outcome = FactorA FactorB FactorC; lsmeans FactorA FactorB FactorC / adjust=tukey pdiff=all alpha=0.05 cl; ods output diff = GLM_DIFF; run; /* previously offline this would work */
proc means data = GLM_DIFF; var _1 _2 _3; run;
/* but fields are now 1 2 3 */
/* and this fails */
proc means data = GLM_DIFF;
var 1 2 3;
run;
I can't figure out what the correct syntax should be. Can someone help?
Thanks
Hello,
I think this can be solved by a SAS Name Literal.
Enclose variable name or data set name in quotes immediately followed by little n.
Like in:
data sedanTypes;
set cars;
by 'Sedan Types'n;
if 'first.Sedan Types'n then type=1;
run;
See documentation for
Using Name Literals and Avoiding Errors When Using Name Literals.
Koen
It could also be that you are looking at the labels, being 1,2 & 3.
The variable names may still contain an underscore as a prefix.
Koen
I'm afraid that didn't work for me. I tried
proc means data = GLM_DIFF; var 'GLM_DIFF'1; run;
And other such variations.
Check the setting of the VALIDVARNAME option.
If you have VALIDVARNAME=V7 then you cannot create a variable with a name like 1.
If you have VALIDVARNAME=ANY then you can. If you have created datasets with names like that then you need to use name literal to reference the variables.
proc means data = GLM_DIFF;
var '1'n '2'n '3'n;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.