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 more