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?
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.
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.