Learning SAS? Welcome to the exclusive online community for all SAS learners.

Variable Name in SAS Studio OnDemand

Reply
Occasional Contributor
Posts: 10

Variable Name in SAS Studio OnDemand

I am new to the SAS Studio OnDemand.  I imported a data set into my library in SAS Studio and I can see that I do have a character variable by the name "Coverage Major" in a data set named as Glass.  To limit my analysis to only the "PD" type of the coverage, I wrote the following line in my code:

 

where coverage_major="PD";

 

but I got an error message saying that "variable coverage_major is not on file SASUSER.GLASS".  I also tried writing the name of the variable as "coverage major" or "Coverage_Major", but still get the same error message.  Any clue?

 

Thank you.  

 

 

Super User
Posts: 10,516

Re: Variable Name in SAS Studio OnDemand

Can you post from the log the code you ran with the error message?

 

 

Super User
Posts: 17,865

Re: Variable Name in SAS Studio OnDemand

Run a proc contents to see the variable name and label. 

 

proc contents data=sashelp.class;
run;
Occasional Contributor
Posts: 10

Re: Variable Name in SAS Studio OnDemand

Did that and the name of the variable from Proc Content is exactly the same as I was describing it.  Please see the attachment.  

 

It says the name is "Coverage Major" and so should I write the name using the conventional way, i.e., coverage_major, in my code?  Or how?  

Super User
Posts: 10,516

Re: Variable Name in SAS Studio OnDemand

That data set is using a feature that is not popular among some of the more conservative SAS users, such as myself, that allows variable names with spaces and such. One reason is the problem you already discovered. To use literal names like that you have to enclose the variable name in quotes and have an n immediately following the last quote:

 

'Coverage Major'n

for example.

 

You may get tired of typing all those quotes and n. I find it tedious and either avoid creating variables with those names or rename for my use as possible.

Occasional Contributor
Posts: 10

Re: Variable Name in SAS Studio OnDemand

Thanks, it works.  

Super User
Posts: 17,865

Re: Variable Name in SAS Studio OnDemand

If you have a program you're working on and can rerun your analysis without too much issue, I would consider setting your validvarname option to V7. Then you'll have the standard SAS names you expect. Otherwise, you'll need to keep typing your spaces and quotation marks, and guessing at variable names vs labels. 

 

 

options validvarname=v7;

 

 

Ask a Question
Discussion stats
  • 6 replies
  • 269 views
  • 0 likes
  • 3 in conversation