<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Importing excel file with sheet name that has ampersand or percent sign using %superq() in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/282599#M269854</link>
    <description>&lt;P&gt;I dont have an answer for your question but that seems overly complex.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can assign a libname can you use proc copy instead. Or can you use NLITERAL() to read in sheet names.&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jul 2016 02:23:42 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-07-07T02:23:42Z</dc:date>
    <item>
      <title>Importing excel file with sheet name that has ampersand or percent sign using %superq() in macro sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/282589#M269853</link>
      <description>&lt;P&gt;I'm creating a macro that recursively imports multiple excel files that have&amp;nbsp;multiple sheets within each excel file. Some sheet names contain special characters (i.e. ampersand, % sign) so I want to incorporate %superQ() in my importing macro to mask these special characters. But when I run I get an error: invalid symbolic variable name 'value'. Can someone please let me know what I'm doing wrong? &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an extract of my macro :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro imp;
 data _null_;
   set file_directory (where=(prxmatch('/(xls|csv)/i',FileType)));
   call symput('path'||left(_n_),strip(path));
   call symput('filen'||left(_n_),strip(filename));
   call symput('table'||left(_n_),cats("File",(_n_)));
   call symput('type'||left(_n_),strip(upcase(filetype)));
   call symput('stop',strip(_n_));
 run;
&lt;BR /&gt;%do i=1 %to &amp;amp;stop.; /* Enter into excel library to extract sheetnames from each file. */
 %if %substr(&amp;amp;&amp;amp;type&amp;amp;i,1,3) eq XLS %then %do;
  libname excellib excel "&amp;amp;&amp;amp;path&amp;amp;i.\&amp;amp;&amp;amp;filen&amp;amp;i"; 
   proc sql noprint; 
      create table sheetname&amp;amp;i. as /* Return a distinct list of sheetnames from each file. */
      select distinct Path, Filename, SheetName
      from (select "&amp;amp;&amp;amp;path&amp;amp;i." as Path, "&amp;amp;&amp;amp;filen&amp;amp;i" as FileName, 
      case when prxmatch('/(_xlnm#)/i',memname) 
      then tranwrd(compress(substr(memname,1,index(memname,'_xlnm#')-1),"$",""),"''","'")
      else tranwrd(compress(memname,"$",""),"''", "'") end as SheetName
      from sashelp.vstabvw where libname="EXCELLIB");
&lt;BR /&gt;/* Assign macros to sheet names that are to be imported. */
      select count(DISTINCT sheetname) into :cnt_sht
      from sheetname&amp;amp;i.;
      select DISTINCT sheetname into :sheet1 - :sheet%left(&amp;amp;cnt_sht)
      from sheetname&amp;amp;i.;
   quit;&lt;BR /&gt;  libname excellib clear;
 &lt;BR /&gt; do j=1 %to &amp;amp;cnt_sht; /* Loop through to import multiple sheets per excel file. */
   proc import datafile="&amp;amp;&amp;amp;path&amp;amp;i.\&amp;amp;&amp;amp;filen&amp;amp;i" 
   out=&amp;amp;&amp;amp;table&amp;amp;i.._SH&amp;amp;j. replace; /* Each output is named with a suffix _SH1 to n (=maximum number of sheets found). */
   sheet=&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;"%superq(&amp;amp;&amp;amp;sheet&amp;amp;j)"; /*this is where i get an error*/&lt;/STRONG&gt;&lt;/FONT&gt;
   getnames=yes;
   mixed=yes;
   scantext=yes;
 run;
%end;&lt;BR /&gt;%mend;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 01:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/282589#M269853</guid>
      <dc:creator>dl0324</dc:creator>
      <dc:date>2016-07-07T01:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Importing excel file with sheet name that has ampersand or percent sign using %superq() in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/282599#M269854</link>
      <description>&lt;P&gt;I dont have an answer for your question but that seems overly complex.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can assign a libname can you use proc copy instead. Or can you use NLITERAL() to read in sheet names.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 02:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/282599#M269854</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-07T02:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Importing excel file with sheet name that has ampersand or percent sign using %superq() in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/282627#M269855</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the doc for the %SUPERQ function, you must specify the name of a macro var without the ampercent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However you can use an &amp;amp;suffix, see also code below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sheet1 = %nrstr(cars&amp;amp;more);
%let sheet2 = %nrstr(others&amp;amp;more);

%let i = 1;

%put NOTE: *%superq(sheet&amp;amp;i)*;

proc import
  datafile="c:\temp\cars.xlsx" 
  out=work.sample 
  dbms=xlsx
  replace
;
  sheet="%superq(sheet&amp;amp;i)";
  getnames=yes;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 07:21:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/282627#M269855</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-07-07T07:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: Importing excel file with sheet name that has ampersand or percent sign using %superq() in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/630486#M269856</link>
      <description>&lt;P&gt;data ab;&lt;BR /&gt;input name$ @@;&lt;BR /&gt;datalines;&lt;BR /&gt;a b c d e f g h i j k&lt;BR /&gt;run;&lt;BR /&gt;/* above-mentioned observations are sheet names&lt;BR /&gt;we can link this to our sheet name and dataset name*/&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set ab nobs=total;&lt;BR /&gt;call symputx("sheet"||left(_n_),name);&lt;BR /&gt;call symputx("cnt",total);&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;sheet2;/* check it's resovling or not in log*/&lt;BR /&gt;%put &amp;amp;cnt; /* check it's resovling or not in log*/&lt;/P&gt;&lt;P&gt;%macro import();&lt;BR /&gt;%do i=1 %to &amp;amp;cnt;&lt;BR /&gt;proc import datafile="G:\SAS Practice\Result\raju.xlsx"&lt;BR /&gt;out=&amp;amp;&amp;amp;sheet&amp;amp;i&lt;BR /&gt;dbms=xlsx&lt;BR /&gt;replace;&lt;BR /&gt;sheet="&amp;amp;&amp;amp;sheet&amp;amp;i";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend import;&lt;BR /&gt;%import();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Mar 2020 14:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/630486#M269856</guid>
      <dc:creator>rajupottala</dc:creator>
      <dc:date>2020-03-08T14:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Importing excel file with sheet name that has ampersand or percent sign using %superq() in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/653870#M269857</link>
      <description>thanks &amp;lt;a href="&lt;A href="https://communities.sas.com/" target="_blank"&gt;https://softballabox.com/"&amp;gt;Softball&lt;/A&gt; Drills&amp;lt;/a&amp;gt;</description>
      <pubDate>Sat, 06 Jun 2020 06:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-excel-file-with-sheet-name-that-has-ampersand-or/m-p/653870#M269857</guid>
      <dc:creator>sam01</dc:creator>
      <dc:date>2020-06-06T06:38:42Z</dc:date>
    </item>
  </channel>
</rss>

