BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
paulkaefer
Lapis Lazuli | Level 10

See test code and Excel file, attached.

 

In sheet test1, cell A1 is "S&P 500" (without quotes). Proc import reads this fine.

 

In sheet test2, cell A1 links to another sheet, which has the value "S&P 500" (once again, no quotes in the cell itself).

Proc import reads this as "S&P 500". I recognize this as a character encoding for & used in HTML, etc.

 

Is there a way to force SAS to not do this? Some option for import?

 

Let me know if this would be more appropriate to post in the General SAS Programming forum.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@ballardw wrote:

Did you try the File Save As to CSV? I did with your example file and did not get the &amp when saving the Test2 tab to csv.


Since an CSV file by definition cannot contain any linked cells that would remove the symptom, but it is not a fix to reading the XLSX file directly.

 

The OP should report this behavior to SAS and see if they are planning any updates to fix it.

View solution in original post

9 REPLIES 9
utrocketeng
Quartz | Level 8
try something like this at the top of your code:

options validvarname=v7;
paulkaefer
Lapis Lazuli | Level 10

Thanks for the quick response @utrocketeng. I'm still seeing & in this variable (note that I don't want this to be a variable name but a value). I tried with validvarname=any; and still am seeing & appear.

ballardw
Super User

@paulkaefer wrote:

Thanks for the quick response @utrocketeng. I'm still seeing & in this variable (note that I don't want this to be a variable name but a value). I tried with validvarname=any; and still am seeing & appear.


Things like &amp often indicate the file is actually HTML of some flavor and the source is lying to you by changing the file extension.

OR some other behavior such as copy and paste from a document in html format.

 

Do a file save as CSV for each sheet and import that..

paulkaefer
Lapis Lazuli | Level 10

Thanks, @ballardw. Not an ideal solution, but that could work in a pinch.

 

We know the origin to be Excel. As my example shows, this only appears if you import a sheet where cells pull their value from another sheet. Both examples have the same human-readable value, but something in the import is converting one of the ampersands to &.

ballardw
Super User

Did you try the File Save As to CSV? I did with your example file and did not get the &amp when saving the Test2 tab to csv.

Tom
Super User Tom
Super User

@ballardw wrote:

Did you try the File Save As to CSV? I did with your example file and did not get the &amp when saving the Test2 tab to csv.


Since an CSV file by definition cannot contain any linked cells that would remove the symptom, but it is not a fix to reading the XLSX file directly.

 

The OP should report this behavior to SAS and see if they are planning any updates to fix it.

Ksharp
Super User
data _null_;
x=htmldecode("S&P 500");
put x=;
run;
paulkaefer
Lapis Lazuli | Level 10

Thanks for the example of htmldecode, @Ksharp. Another option would be to do the following:

 

select tranwrd(A, "&", "&") as A_new

I submitted a track with tech support as @Tom suggests, and marked that comment as solution. I agree, the workarounds are not a fix for directly reading such an Excel file, but they can help in a pinch.

paulkaefer
Lapis Lazuli | Level 10

I just wanted to loop back on this. As @Tom suggested, I opened a track with SAS tech support. The specialist responded that this has been fixed in the 9.4m5 release.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 3574 views
  • 1 like
  • 5 in conversation