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

 am using a SAS procedure that produces an ods output dataset that contains variables that have a period (dot) in their name (example p0.5. A minimum example for reproducing this behavior in SAS 9.4 TS Level 1M1 running on AIX is below.

 

I would like to do something with these variables later in a datastep, let's say assigning it's value to another variable. But when I use a variable name such as p0.5, I get a "ERROR 386-185: Expecting an arithmetic expression. ERROR 201-322: The option is not recognized and will be ignored." error message, which I interpret as SAS not understanding that I wish to refer to the variable (and instead trying to interpret this as some kind of arithmetic expression). I tried things like p05 or p0_5, but these result in "Variable p05 is uninitialized." I could not find any information about this situation (but perhaps I have just not used for the right information search terms).

 

Any ideas on how to do anything with this variable?

 

data test;
  y=1; se=10;output;
  y=2; se=10;output;
  y=1.5; se=10;output;
run;

ods output PostSummaries=PostSummaries PostIntervals=PostIntervals;
proc mcmc data=test statistics(PERCENT=(0.025 0.5 0.975))=(SUMMARY INTERVAL);
  parms mu 1.5;   
  prior mu ~ normal(0, sd=10);
  model y ~ normal(mu,sd=se);   
run;

data posterior;
  merge PostSummaries(where=(parameter="mu")) PostIntervals(where=(parameter="mu"));
  by parameter;
run;

proc contents;
run;

 

Here is the output of the proc contents:

The CONTENTS Procedure                                                 
                                                                                                                        
             Data Set Name        WORK.POSTERIOR                                   Observations          1              
             Member Type          DATA                                             Variables             12             
             Engine               V9                                               Indexes               0              
             Created              01/25/2017 15:46:35                              Observation Length    96             
             Last Modified        01/25/2017 15:46:35                              Deleted Observations  0              
             Protection                                                            Compressed            NO             
             Data Set Type                                                         Sorted                NO             
             Label                                                                                                      
             Data Representation  HP_UX_64, RS_6000_AIX_64, SOLARIS_64, HP_IA64                                         
             Encoding             latin1  Western (ISO)                                                                 
                                                                                                                        
                                                                                                                        
                                           Engine/Host Dependent Information                                            
                                                                                                                        
          Data Set Page Size          65536                                                                             
          Number of Data Set Pages    1                                                                                 
          First Data Page             1                                                                                 
          Max Obs per Page            681                                                                               
          Obs in First Data Page      1                                                                                 
          Number of Data Set Repairs  0                                                                                 
          Filename                    /proj/sastmp/saswork/SAS_work432E00A802D4_chbsux0577/posterior.sas7bdat           
          Release Created             9.0401M1                                                                          
          Host Created                AIX                                                                               
          Inode Number                454799                                                                            
          Access Permission           rw-rw-rw-                                                                         
          Owner Name                  xxxxxxx                                                                          
          File Size (bytes)           131072                                                                            
                                                                                                                        
                                                                                                                        
                                       Alphabetic List of Variables and Attributes                                      
                                                                                                                        
                            #    Variable         Type    Len    Format    Label                                        
                                                                                                                        
                            8    Alpha            Num       8    D5.                                                    
                            9    CredibleLower    Num       8    D8.                                                    
                           10    CredibleUpper    Num       8    D8.                                                    
                           11    HPDLower         Num       8    D8.                                                    
                           12    HPDUpper         Num       8    D8.                                                    
                            3    Mean             Num       8    D8.                                                    
                            2    N                Num       8    8.                                                     
                            6    P0.5             Num       8    D8.       0.5                                          
                            5    P0.025           Num       8    D8.       0.025                                        
                            7    P0.975           Num       8    D8.       0.975                                        
                            1    Parameter        Char      2                                                           
                            4    StdDev           Num       8    D8.       Standard Deviation                           
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

'p0.5'n  the quotes are needed because when special characters are allowed in variable names they might include spaces and the quotes indicate the whole name the trailing n tells SAS to use the string as a variable name.

 

Though my preference would be fix the process that is generating the names to use typical SAS names unless those variables are in an external database.

View solution in original post

5 REPLIES 5
ballardw
Super User

'p0.5'n  the quotes are needed because when special characters are allowed in variable names they might include spaces and the quotes indicate the whole name the trailing n tells SAS to use the string as a variable name.

 

Though my preference would be fix the process that is generating the names to use typical SAS names unless those variables are in an external database.

BjoernHolzhauer
Obsidian | Level 7

Thanks, the 'p0.5'n approach solved the problem. I actually tried to convince SAS not to do this, but options validvarname=v6 did not avoid it...

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Crikey, not seen this before.  A SAS procedure creating a dataset with non-SAS compliant variable names?  Anyways, when I run that on my machine the variable names use underscore rather than a dot:

P_05

For example.  All I can think of is that you have some options set -

options validavarname=any;

For instance allows anything, non-standard SAS names included.  I would avoid using that, and get varnames in a proper compliant manner. 

You should however be able to reference them using named literals:

'P.05'n

However, as above I really recommend not doing this.  Try to change your system options to only allow standard SAS naming.

BjoernHolzhauer
Obsidian | Level 7
Thanks! The 'p0.5'n approach solved the problem. I actually tried to convince SAS not to do this, but options validvarname=v6 did not avoid it. Beyond that, I cannot easily change settings in our system, but I will let people know.
data_null__
Jade | Level 19

@RW9 wrote:

Hi,

 

Crikey, not seen this before.  A SAS procedure creating a dataset with non-SAS compliant variable names?  Anyways, when I run that on my machine the variable names use underscore rather than a dot:

P_05

For example.  All I can think of is that you have some options set -

options validavarname=any;

For instance allows anything, non-standard SAS names included.  I would avoid using that, and get varnames in a proper compliant manner. 

You should however be able to reference them using named literals:

'P.05'n

However, as above I really recommend not doing this.  Try to change your system options to only allow standard SAS naming.


 

There is no mistery here your machine has different defaults.

options validvarname=V7;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 5 replies
  • 16128 views
  • 2 likes
  • 4 in conversation