<?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: Pass in quoted string list with space in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505313#M135300</link>
    <description>&lt;P&gt;Use a libname instead?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myXL xlsx 'path to file';



proc copy in=myXL out=work;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241069"&gt;@qw213&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to read in&amp;nbsp;selected tabs from a excel file and append them into one dataset. I have created a macro variable called TabList where the values are quoted strings with spaces in them (e.g. "aaa bbb","bbb ccc"...) as this is how the sheets are named. I am having trouble passing the list in macro. I am getting the following error with the code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select Tab into :TabList separated by ","&lt;BR /&gt;from mapping;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro process;&lt;BR /&gt;%let n=%sysfunc(countw("&amp;amp;TabList.", ',' ));&lt;BR /&gt;%put &amp;amp;n;&lt;BR /&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;%let val = %scan(&amp;amp;TabList.,&amp;amp;i);&lt;/P&gt;
&lt;P&gt;%put &amp;amp;val &amp;amp;i &amp;amp;n;&lt;/P&gt;
&lt;P&gt;OPTION VALIDVARNAME=V7;&lt;BR /&gt;PROC IMPORT DATAFILE= &amp;amp;in_dir.&lt;BR /&gt;OUT=&amp;nbsp;data&lt;BR /&gt;DBMS=XLSX&lt;BR /&gt;REPLACE;&lt;BR /&gt;SHEET= &amp;amp;val;&lt;BR /&gt;GETNAMES=NO;&lt;BR /&gt;datarow=3;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%process;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Oct 2018 19:55:34 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-10-17T19:55:34Z</dc:date>
    <item>
      <title>Pass in quoted string list with space in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505312#M135299</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to read in&amp;nbsp;selected tabs from a excel file and append them into one dataset. I have created a macro variable called TabList where the values are quoted strings with spaces in them (e.g. "aaa bbb","bbb ccc"...) as this is how the sheets are named. I am having trouble passing the list in macro. I am getting the following error with the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select Tab into :TabList separated by ","&lt;BR /&gt;from mapping;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro process;&lt;BR /&gt;%let n=%sysfunc(countw("&amp;amp;TabList.", ',' ));&lt;BR /&gt;%put &amp;amp;n;&lt;BR /&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;%let val = %scan(&amp;amp;TabList.,&amp;amp;i);&lt;/P&gt;&lt;P&gt;%put &amp;amp;val &amp;amp;i &amp;amp;n;&lt;/P&gt;&lt;P&gt;OPTION VALIDVARNAME=V7;&lt;BR /&gt;PROC IMPORT DATAFILE= &amp;amp;in_dir.&lt;BR /&gt;OUT=&amp;nbsp;data&lt;BR /&gt;DBMS=XLSX&lt;BR /&gt;REPLACE;&lt;BR /&gt;SHEET= &amp;amp;val;&lt;BR /&gt;GETNAMES=NO;&lt;BR /&gt;datarow=3;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%process;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 19:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505312#M135299</guid>
      <dc:creator>qw213</dc:creator>
      <dc:date>2018-10-17T19:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: Pass in quoted string list with space in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505313#M135300</link>
      <description>&lt;P&gt;Use a libname instead?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myXL xlsx 'path to file';



proc copy in=myXL out=work;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241069"&gt;@qw213&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to read in&amp;nbsp;selected tabs from a excel file and append them into one dataset. I have created a macro variable called TabList where the values are quoted strings with spaces in them (e.g. "aaa bbb","bbb ccc"...) as this is how the sheets are named. I am having trouble passing the list in macro. I am getting the following error with the code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select Tab into :TabList separated by ","&lt;BR /&gt;from mapping;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro process;&lt;BR /&gt;%let n=%sysfunc(countw("&amp;amp;TabList.", ',' ));&lt;BR /&gt;%put &amp;amp;n;&lt;BR /&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;%let val = %scan(&amp;amp;TabList.,&amp;amp;i);&lt;/P&gt;
&lt;P&gt;%put &amp;amp;val &amp;amp;i &amp;amp;n;&lt;/P&gt;
&lt;P&gt;OPTION VALIDVARNAME=V7;&lt;BR /&gt;PROC IMPORT DATAFILE= &amp;amp;in_dir.&lt;BR /&gt;OUT=&amp;nbsp;data&lt;BR /&gt;DBMS=XLSX&lt;BR /&gt;REPLACE;&lt;BR /&gt;SHEET= &amp;amp;val;&lt;BR /&gt;GETNAMES=NO;&lt;BR /&gt;datarow=3;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%process;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 19:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505313#M135300</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-17T19:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Pass in quoted string list with space in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505320#M135301</link>
      <description>&lt;P&gt;Thank you for your response. I don't have issue reading in the sheets. The issue mainly was that I have to loop through the wanted sheets and perform a few operations, but I can't pass the list with quoted strings into the macro function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically I can't even count the number of strings correctly to begin with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 20:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505320#M135301</guid>
      <dc:creator>qw213</dc:creator>
      <dc:date>2018-10-17T20:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Pass in quoted string list with space in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505323#M135303</link>
      <description>&lt;P&gt;You don't have to put quotes, just separate by comma and then extract the sheet name using SCAN with delimiter as comma and mention the macro for sheet name in quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let TabList=aaa bbb,bbb ccc;


%macro process;
%let n=%sysfunc(countw("&amp;amp;TabList.", ',' ));
%put &amp;amp;n;
%do i=1 %to &amp;amp;n;
%let val = %scan(%bquote(&amp;amp;TabList.),&amp;amp;i,',');

%put &amp;amp;val &amp;amp;i &amp;amp;n;

OPTION VALIDVARNAME=V7;
PROC IMPORT DATAFILE= &amp;amp;in_dir.
OUT= data
DBMS=XLSX
REPLACE;
SHEET= "&amp;amp;val";
GETNAMES=NO;
datarow=3;
RUN;

%end;
%mend;

%process;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Oct 2018 20:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505323#M135303</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-10-17T20:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Pass in quoted string list with space in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505331#M135307</link>
      <description>&lt;P&gt;This part is giving a problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let val = %scan(&amp;amp;TabList.,&amp;amp;i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try replacing it with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let val %scan(%bquote(&amp;amp;TabList.),&amp;amp;i.,%str(,));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Reference&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/39889137/error-in-simple-sas-macro" target="_blank"&gt;https://stackoverflow.com/questions/39889137/error-in-simple-sas-macro&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 20:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505331#M135307</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2018-10-17T20:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Pass in quoted string list with space in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505332#M135308</link>
      <description>Thanks! This works perfectly.</description>
      <pubDate>Wed, 17 Oct 2018 20:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505332#M135308</guid>
      <dc:creator>qw213</dc:creator>
      <dc:date>2018-10-17T20:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Pass in quoted string list with space in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505375#M135333</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241069"&gt;@qw213&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks! This works perfectly.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I generally avoid using commas inside macro value lists as you then have to add code to pass them to other macros. If the sole purpose is to have a delimiter other than space try a different character that shouldn't appear in the values such as # and use that for the delimiter in countw, scan, %scan etc.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 22:02:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-in-quoted-string-list-with-space-in-macro/m-p/505375#M135333</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-17T22:02:46Z</dc:date>
    </item>
  </channel>
</rss>

