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

I am using a dataset that includes a variable called "År för träff". I want to rename the variable to "visityear" but SAS does not recognise the variable name "År för träff". I have tried: 
options validmemname=extend;
options validvarname=any;

rename "År för träff"n=visityear;


but I get error messages. Does anyone know how to solve this? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What encoding is your session using. 

Here is a test program that works fine for me in a SAS session using UTF-8 encoding and one using WLATIN1 encoding.  Note that when I pasted the code into the editor in the WLATIN1 session it automatically changed the encoding of the name in the code.  You can tell because Display Manager logs do not support UTF-8 encoding. So the log from the UTF-8 session looks different because it is trying the display the bytes in the UTF-8 string using the single byte encodings of WLATIN1.

options validvarname=any;
data test;
  "År för träff"n=2020;
run;

proc datasets nolist lib=work;
modify test;
  rename "År för träff"n=visityear;
run;
quit;

%put %sysfunc(getoption(encoding));
342   options validvarname=any;
343   data test;
344     "År för träff"n=2020;
345   run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.03 seconds


346
347   proc datasets nolist lib=work;
348   modify test;
349     rename "År för träff"n=visityear;
NOTE: Renaming variable 'År för träff'n to visityear.
350   run;

NOTE: MODIFY was successful for WORK.TEST.DATA.
351   quit;

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.05 seconds
      cpu time            0.03 seconds


352   %put %sysfunc(getoption(encoding));
UTF-8
77    options validvarname=any;
78    data test;
79      "År för träff"n=2020;
80    run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.03 seconds


81
82    proc datasets nolist lib=work;
83    modify test;
84      rename "År för träff"n=visityear;
NOTE: Renaming variable 'År för träff'n to visityear.
85    run;

NOTE: MODIFY was successful for WORK.TEST.DATA.
86    quit;

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds


87
88    %put %sysfunc(getoption(encoding));
WLATIN1

How did the variable get created with that name?  Perhaps you can just change the step that is making the dataset.

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

What encoding is your session using. 

Here is a test program that works fine for me in a SAS session using UTF-8 encoding and one using WLATIN1 encoding.  Note that when I pasted the code into the editor in the WLATIN1 session it automatically changed the encoding of the name in the code.  You can tell because Display Manager logs do not support UTF-8 encoding. So the log from the UTF-8 session looks different because it is trying the display the bytes in the UTF-8 string using the single byte encodings of WLATIN1.

options validvarname=any;
data test;
  "År för träff"n=2020;
run;

proc datasets nolist lib=work;
modify test;
  rename "År för träff"n=visityear;
run;
quit;

%put %sysfunc(getoption(encoding));
342   options validvarname=any;
343   data test;
344     "År för träff"n=2020;
345   run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.03 seconds


346
347   proc datasets nolist lib=work;
348   modify test;
349     rename "År för träff"n=visityear;
NOTE: Renaming variable 'År för träff'n to visityear.
350   run;

NOTE: MODIFY was successful for WORK.TEST.DATA.
351   quit;

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.05 seconds
      cpu time            0.03 seconds


352   %put %sysfunc(getoption(encoding));
UTF-8
77    options validvarname=any;
78    data test;
79      "År för träff"n=2020;
80    run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.03 seconds


81
82    proc datasets nolist lib=work;
83    modify test;
84      rename "År för träff"n=visityear;
NOTE: Renaming variable 'År för träff'n to visityear.
85    run;

NOTE: MODIFY was successful for WORK.TEST.DATA.
86    quit;

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds


87
88    %put %sysfunc(getoption(encoding));
WLATIN1

How did the variable get created with that name?  Perhaps you can just change the step that is making the dataset.

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
  • 1 reply
  • 2241 views
  • 0 likes
  • 2 in conversation