I have a .xlsx file which contains the string "X&Y" in a cell. I read it into SAS using the following code:
libname x xlsx "%sysfunc(pathname(work))\pvsds2.xlsx";
data new;
set x.'Sheet1'n ;
run;
In the dataset new, the value appears as "X&Y". Am I doing something wrong, or is the XLSX libname engine failing to properly handle the XML in which the XLSX file is encoded?
I am using Enterprise Guide 7.13 on SAS 9.4 on Linux.
The underlying file is xml or XLSX? If it's XML use the XML engine not the XLSX.
Interesting question.
You are reading the XLSX from your WORK directory so I assume you've created this XLSX with SAS. If so then how do you know that the & encoding happens when you read the sheet and doesn't already get written this way to the sheet in an earlier step?
data new; set x.'Sheet1$'n ; run;
This could work ? libname x xlsx "%sysfunc(pathname(work))\pvsds2.xlsx"; proc copy in=x out=work noclone; run;
Oh, I misunderstood. Try this function. data x; x='X&Y'; correct=htmldecode(x); run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.