BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jayakumarmm
Quartz | Level 8

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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);

View solution in original post

7 REPLIES 7
Reeza
Super User

How are you importing your data?

 

jayakumarmm
Quartz | Level 8

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;
Reeza
Super User

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

 

 

jayakumarmm
Quartz | Level 8
Forum is displaying the same & values which I have updated.
Reeza
Super User

To remove the quotes use compress() on the field. 

 

 

Ksharp
Super User

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;

Tom
Super User Tom
Super User

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);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 2381 views
  • 2 likes
  • 4 in conversation