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

Hello all, 

I am getting the above error with a rename statement.  Here is my code.

Data datasets.redcap_PDE1;
set datasets.redcap_pde0 (Rename=(gest_age = gestational age weeks days

***ERROR 79-322: Expecting a =.*****
mri_performed=MRI performed
age_mri_diag_days=Age in days at time of MRI
mri_spec=MRI interpretation
diag_mri=MRI result
diag_iq=Development IQ
diag_iq_norm_range=IQ Range));
run;

I feel as though I'm missing something very obvious. 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Your rename list needs an ending ) and is expecting a new name for Age (and Weeks and days) which I suspect do not actually exist.

Rename are pairs, oldname = newname. You cannot have a space in a name. If you expected to rename that variable to something containing all these words: gestational age weeks days you would need to either use an _ instead of space: =gestational_age_weeks_days or set system options to allow valid variables names with spaces which would then be referenced as "gestational age weeks days"n everywhere the variable is used.

 

You repeatedly use things with spaces that are not valid: The spaces above the ^ are all invalid.

mri_spec=MRI interpretation
            ^
diag_mri=MRI result
            ^
diag_iq=Development IQ
                   ^ 
diag_iq_norm_range=IQ Range
                     ^

Suggestion: Do not rename the variables but supply a LABEL for the variables

Data datasets.redcap_PDE1;
   set datasets.redcap_pde0;
   label
      gest_age = "Gestational age weeks days"
      mri_performed="MRI performed"
      age_mri_diag_days="Age in days at time of MRI"
      mri_spec="MRI interpretation"
      diag_mri="MRI result"
      diag_iq="Development IQ"
      diag_iq_norm_range="IQ Range"
   ;
run;

/* see how labels are used*/
Proc print data=datasets.redcap_PDE1 label;
run;

Labels can be up to 256 characters currently where variable names are limited to 32. So you can provide much nicer descriptions when needed.

 

Most procedures will display the label by default, proc print isn't so you specify the option. One of the nice things about labels is can supply a label that is only used for a specific procedure. This is often helpful when you use a long label to document information about a variable (your "age weeks days" for example) but for a specific table you only want to see "Gestational Age". So for that procedure you add a statement:

Label gest_age="Gestational Age";

 

 

Hint when asking about errors or other messages: Copy the entire step from the log with all the notes and errors; on the forum open a text box using the </> icon that appears above the message window and paste the text. The text box will preserve formatting of text such as the error message you show that likely had some diagnostic characters as to exactly where the = was expected.

View solution in original post

5 REPLIES 5
ballardw
Super User

Your rename list needs an ending ) and is expecting a new name for Age (and Weeks and days) which I suspect do not actually exist.

Rename are pairs, oldname = newname. You cannot have a space in a name. If you expected to rename that variable to something containing all these words: gestational age weeks days you would need to either use an _ instead of space: =gestational_age_weeks_days or set system options to allow valid variables names with spaces which would then be referenced as "gestational age weeks days"n everywhere the variable is used.

 

You repeatedly use things with spaces that are not valid: The spaces above the ^ are all invalid.

mri_spec=MRI interpretation
            ^
diag_mri=MRI result
            ^
diag_iq=Development IQ
                   ^ 
diag_iq_norm_range=IQ Range
                     ^

Suggestion: Do not rename the variables but supply a LABEL for the variables

Data datasets.redcap_PDE1;
   set datasets.redcap_pde0;
   label
      gest_age = "Gestational age weeks days"
      mri_performed="MRI performed"
      age_mri_diag_days="Age in days at time of MRI"
      mri_spec="MRI interpretation"
      diag_mri="MRI result"
      diag_iq="Development IQ"
      diag_iq_norm_range="IQ Range"
   ;
run;

/* see how labels are used*/
Proc print data=datasets.redcap_PDE1 label;
run;

Labels can be up to 256 characters currently where variable names are limited to 32. So you can provide much nicer descriptions when needed.

 

Most procedures will display the label by default, proc print isn't so you specify the option. One of the nice things about labels is can supply a label that is only used for a specific procedure. This is often helpful when you use a long label to document information about a variable (your "age weeks days" for example) but for a specific table you only want to see "Gestational Age". So for that procedure you add a statement:

Label gest_age="Gestational Age";

 

 

Hint when asking about errors or other messages: Copy the entire step from the log with all the notes and errors; on the forum open a text box using the </> icon that appears above the message window and paste the text. The text box will preserve formatting of text such as the error message you show that likely had some diagnostic characters as to exactly where the = was expected.

kristiepauly
Obsidian | Level 7

Thanks for that explanation @ballardw

I initially used label statements, and it was working but in trying to fix some other code I came across some old notes that said to NOT use label statements as it would likely cause problems downs the road. It said the preferred method is the rename statement.  From all the comments on this thread, instructing me to use the label statement, it sounds like that isn't true? Is there a reason to use one over the other or just user preference? 

ballardw
Super User

@kristiepauly wrote:

Thanks for that explanation @ballardw

I initially used label statements, and it was working but in trying to fix some other code I came across some old notes that said to NOT use label statements as it would likely cause problems downs the road. It said the preferred method is the rename statement.  From all the comments on this thread, instructing me to use the label statement, it sounds like that isn't true? Is there a reason to use one over the other or just user preference? 


I would have to see a complete discussion of exactly what was said in this regard. Most likely it would have involved moving the data from SAS to another data system as most do not have any concept of "label" and so labels would not automagically transfer to another data system. The ability of SAS to handle the name literals was basically added to handle names from other data systems that have much looser rules for things like spaces, and characters such as *()[] and so on as part of the SAS Access to different external databases. If you need to transfer the results to another data and "rename" seems desirable I would say wait until the actual step that transfers the data.

Maybe by that time you'll have enough experience to write renames that are syntactically correct.

 

If you are going to write models, summaries, reports, do analysis and/or graphs inside SAS then Labels are much more flexible.

Tom
Super User Tom
Super User

What the error is saying is that you need to use an equal sign for every pair of names.

So something like:

 

 gest_age = gestational
 age = weeks 

But I suspect that is not what you are actually trying to do.

 

Either you need to use new names that are valid names:

 

gest_age = gestational_age_weeks_days

 

Or if you have set the VALIDVARNAME option to ANY  then you could use name literals. 

 

gest_age = 'gestational age weeks days'n

 

But why would you ever do that? It just makes your datasets harder to work with since now you have to use name literals every time you need to reference one of those variables.

 

Perhaps you should attach LABELs to the variables instead.

 

data datasets.redcap_PDE1;
  set datasets.redcap_pde0;
  label
    gest_age = 'gestational age weeks days'
    mri_performed='MRI performed'
    age_mri_diag_days='Age in days at time of MRI'
    mri_spec='MRI interpretation'
    diag_mri='MRI result'
    diag_iq='Development IQ'
    diag_iq_norm_range='IQ Range'
  ;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 2030 views
  • 4 likes
  • 4 in conversation