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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.