BookmarkSubscribeRSS Feed
CaroleBPRI
Calcite | Level 5

Hello SAS community,

 

When I import a xlsx file with SAS 9.4, I 've got an issue with a variable name in a column.

'EQ & PPR' in the xlsx file become 'EQ & PPR' in the SAS table imported.

Is it a bug from SAS? Are there any other misread special characters?

Thank you very much.

 

 

CaroleBPRI_0-1689595692163.png

 

CaroleBPRI_1-1689595883542.png

 

5 REPLIES 5
Tom
Super User Tom
Super User

How was the source file created?

If I make an XLSX with SAS I do not have that problem.

data test;
  infile cards dsd truncover;
  input (x1-x3) (:$20.);
cards;
id,EQ & PR,x
1,2,3
4,5,6
;

filename xlsx temp;
proc export data=test file=xlsx dbms=xlsx ;
  putnames=NO;
run;

options validvarname=v7;
proc import file=xlsx dbms=xlsx out=test2 replace;
run;

proc contents data=test2 varnum;
run;

                 Variables in Creation Order

#    Variable    Type    Len    Format    Informat    Label

1    id          Char      1    $1.       $1.         id
2    EQ___PR     Char      1    $1.       $1.         EQ & PR
3    x           Char      1    $1.       $1.         x
CaroleBPRI
Calcite | Level 5

This is my original Code to import the xlsx file :

proc import out=lst_pci
datafile="V:\3613_DEPT_CONTROLE_DE_GESTION\Transverse\ANAPLAN\TBB Clientèle - Eléments hors SI.xlsx"
dbms=XLSX replace;
Sheet='REF PCI';
run;

Tom
Super User Tom
Super User

You could probably open a support ticket with SAS to have them actually look at that file and see what is happening.

 

If you just want to change the variable names to replace HTML code like & with its decode should be able to just use the HTMLDECODE() function.

 

Here is an example:

options validvarname=any ;
data lst_pci ;
  length id name 'EQ & PPR'n 8;
run;

proc sql noprint;
select catx('=',nliteral(name),nliteral(htmldecode(name))) 
  into :renames separated by ' '
  from dictionary.columns
  where libname='WORK'
    and memname='LST_PCI'
    and name ne htmldecode(name)
;
quit;

proc datasets nolist lib=work;
  modify lst_pci;
  rename &renames ;
  run;
quit;

proc contents data=lst_pci varnum;
run;
 Variables in Creation Order

#    Variable    Type    Len

1    id          Num       8
2    name        Num       8
3    EQ & PPR    Num       8

Quentin
Super User

If you run PROC CONTENTS on the data, what do you see for the variable name?

 

I can't tell where the image comes from (is it a query builder?).  I"m wondering if whatever tool that is generating the image is the problem, not the dataset itself.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
CaroleBPRI
Calcite | Level 5

Ok I will test this point. Is there still a misread when the table is exported. Thank you

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 5 replies
  • 635 views
  • 0 likes
  • 3 in conversation