Hi,
I am trying to import data from excel into SAS dataset, I am facing issues with data contains double quotes and ampersand.
Code used:
libname xlsFile XLSX "/path/monthly.xlsm"; options validvarname=v7; options SYMBOLGEN MPRINT; PROC SQL; create table work.raw_data as (select * from xlsFile.datal); quit;
Excel data:
1. "Online system" and "Mobile data"
2, Online system & Mobile data
SAS dataset:
1. "Online system" and "Mobile data"
2, Online system & Mobile data
Expected data:
1. Online system and Mobile data
2, Online system & Mobile data
I cannot recreate your problem. When I create an Excel spreadsheet with those values SAS reads them in the same as they are in Excel. What version of SAS and Excel are you using? Why are you using an XLSM file instead of an XLSX file?
Now if you want to remove the quotes from the middle of you string your best option is to just strip them out using the COMPRESS() function.
VAR1 = compress(VAR1,'"');
And if you really do want to translate HTML codes like & back into the characters they represent then use HTMLDECODE() function.
VAR1 = htmldecode(VAR1);
How are you importing your data?
Hi,
Given below is the code
Code used:
libname xlsFile XLSX "/path/monthly.xlsm"; options validvarname=v7; options SYMBOLGEN MPRINT; PROC SQL; create table work.raw_data as (select * from xlsFile.datal); quit;
You can use dequote() to strip quotes or compress() to remove them from the text.
If the text has quotes in Excel it will in SAS and that seems the correct behaviour to me. I also don't get the & converted to HTML (amp) so I think there's something else behind the data in Excel? Or the forum changed the value?
I'm using SAS 9.4 TS1M3 and Excel 2010
I get the following, which is exactly what I'd expect.
"Online system" and "Mobile data"
Online system & Mobile data
To remove the quotes use compress() on the field.
1) try to use PROC IMPORT . 2) data have; a=' "Online system" and "Mobile data" '; b=htmldecode(a);output; a=' Online system & Mobile data '; b=htmldecode(a);output; run;
I cannot recreate your problem. When I create an Excel spreadsheet with those values SAS reads them in the same as they are in Excel. What version of SAS and Excel are you using? Why are you using an XLSM file instead of an XLSX file?
Now if you want to remove the quotes from the middle of you string your best option is to just strip them out using the COMPRESS() function.
VAR1 = compress(VAR1,'"');
And if you really do want to translate HTML codes like & back into the characters they represent then use HTMLDECODE() function.
VAR1 = htmldecode(VAR1);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.