BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
markgewhite
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
If you add the following option to your code or autoexec it should help avoid those issues:


options validvarname=v7;

Then it'll generate them as _1, _2 etc.

View solution in original post

8 REPLIES 8
sbxkoenk
SAS Super FREQ

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

sbxkoenk
SAS Super FREQ

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

markgewhite
Calcite | Level 5
No. The variables are definitely named 1, 2, etc. Thanks, though.
markgewhite
Calcite | Level 5

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.

 

 

Tom
Super User Tom
Super User

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;
markgewhite
Calcite | Level 5
Thanks. I see where you're coming from, but I'm not creating the variable names. ODS is.
Reeza
Super User
If you add the following option to your code or autoexec it should help avoid those issues:


options validvarname=v7;

Then it'll generate them as _1, _2 etc.

markgewhite
Calcite | Level 5
Brilliant. This worked. Thanks. Tom was on the right track.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 8 replies
  • 2371 views
  • 0 likes
  • 4 in conversation