BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
wlierman
Lapis Lazuli | Level 10

I am trying to rename a variable that is labeled (Do Not Modfy) Contact  (modify is misspelled in the file).  I try a simple rename in the Data Step:

Data Arias.System_contacts (rename = ((Do Not Modfy)Contact = Contact_number));
  Set ARIAS.System_Contacts_per_tracer;
run;

That results in the following error:

 

84   Data Arias.System_contacts (rename = ((Do Not Modfy)Contact = Contact_number));
                                           -
                                           214
                                           23
                                            --
                                            79
ERROR 214-322: Variable name ( is not valid.

ERROR 23-7: Invalid value for the RENAME option.

ERROR 79-322: Expecting a =.

85     Set ARIAS.System_Contacts_per_tracer;
86   run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


I've tried some alternatives such as placing the rename  and label statements in the Data Step. But still get an error.

 

Thank you for your assistance in solving this problem.

 

wlierman

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@wlierman wrote:

I am trying to rename a variable that is labeled (Do Not Modfy) Contact  (modify is misspelled in the file).  I try a simple rename in the Data Step:


Do you mean that the variable NAME is (Do Not Modfy) Contact? Not the variable LABEL is (Do Not Modfy) Contact?

 

Try this:

 

proc datasets library=arias nolist; 
modify system_contacts;
rename '(Do Not Modfy) Contact'n = contact_number;
run; quit;

Although your text has a space between Modfy) and Contact, but your code does not. So which is it? You need to pay attention to details like this.

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@wlierman wrote:

I am trying to rename a variable that is labeled (Do Not Modfy) Contact  (modify is misspelled in the file).  I try a simple rename in the Data Step:


Do you mean that the variable NAME is (Do Not Modfy) Contact? Not the variable LABEL is (Do Not Modfy) Contact?

 

Try this:

 

proc datasets library=arias nolist; 
modify system_contacts;
rename '(Do Not Modfy) Contact'n = contact_number;
run; quit;

Although your text has a space between Modfy) and Contact, but your code does not. So which is it? You need to pay attention to details like this.

--
Paige Miller
wlierman
Lapis Lazuli | Level 10

I ran the code and while it may look like there is a space between the ) and Contact there isn't any extra space.  So I ran this

Data Arias.System_contacts (rename = ( '(Do Not Modfy)Contact'n = Contact_number));
  Set ARIAS.System_Contacts_per_tracer;
run;

and got the following log result:

 

99   Data Arias.System_contacts (rename = ( '(Do Not Modfy)Contact'n = Contact_number));
                                            ------------------------
                                            214
                                            23
ERROR 214-322: Variable name '(Do Not Modfy)Contact'n is not valid.

ERROR 23-7: Invalid value for the RENAME option.

100    Set ARIAS.System_Contacts_per_tracer;
101  run;

I tried one additional space between the closing ' and n but still no successful run.

 

Any there another approach?

 

Thanks.

 

wlierman

wlierman
Lapis Lazuli | Level 10

Sorry, but I read right over your solution.  Checking the View Columns the Label is the (Do Not Modfy)Contact but the variable name is _Do_Not_Modify Contact  with modify actually spelled correctly.

 

So thank you for your help.  Still learned something new on the name literal.

 

wlierman

ballardw
Super User

If your variable has characters that are other than a letter, digit or _  character then you have to use the name literal form with is the entire text of the variable enclosed in quotes with an n immediately following.

 

So if your variable name is

(Do Not Modfy)Contact

then you always have to reference it as "

'(Do Not Modfy)Contact'n

or write a data step to read the data such that you don't get such ugly names.

 

wlierman
Lapis Lazuli | Level 10

Yes.  I read right over the solution by Paige.  The label is the ugly expression.  But the variable name is _Do_Not_Modify Contact  which is still not all that straightforward but at least has modify spelled correctly.

 

This also ties to your answer too.  Thank you.

 

wlierman

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 766 views
  • 1 like
  • 3 in conversation