<?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: Using quotes in a macro program in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629385#M186123</link>
    <description>&lt;P&gt;Here is the whole macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options validvarname=any;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro MultImp(dir=,out=);&lt;/P&gt;&lt;P&gt;* dir of filenames;&lt;BR /&gt;%let flnm=%str(%'dir %")&amp;amp;dir.%str(\%" /A-D/B/ON%');&lt;BR /&gt;filename myfiles pipe %unquote(&amp;amp;flnm);&lt;/P&gt;&lt;P&gt;* list of filenames;&lt;BR /&gt;data list;&lt;BR /&gt;length fname $256.;&lt;BR /&gt;infile myfiles truncover;&lt;BR /&gt;input myfiles $100.;&lt;/P&gt;&lt;P&gt;fname=quote(upcase(cats("&amp;amp;dir",'\',myfiles)));&lt;/P&gt;&lt;P&gt;call symput('fname_loc',cats("_","&amp;amp;dir",'\',myfiles));&lt;BR /&gt;out="&amp;amp;out";&lt;BR /&gt;drop myfiles;&lt;/P&gt;&lt;P&gt;* import this range through the list of filenames;&lt;/P&gt;&lt;P&gt;call execute('&lt;BR /&gt;* import excels;&lt;/P&gt;&lt;P&gt;proc import dbms=xlsx out=_test10&lt;BR /&gt;datafile= '||fname||' replace ;&lt;BR /&gt;range="Sheet1$A5:BE2000";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;* varnames without spaces or special chars;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;cats("'",cats(name),"'n","=",compress(name,"_","ADK")) as name1&lt;BR /&gt;/*%str(cats(%"%'%",cats(name),%"%'n%",%"=%",compress(name,%"_%",%"ADK%"))) as name1*/&lt;BR /&gt;into :renamecolumns separated by " "&lt;BR /&gt;from&lt;BR /&gt;dictionary.columns&lt;BR /&gt;where libname="WORK" and&lt;BR /&gt;memname="_TEST10"&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;renamecolumns;&lt;/P&gt;&lt;P&gt;/* Rename the variables */&lt;BR /&gt;data _TEST20;&lt;BR /&gt;set _TEST10 (rename=(&amp;amp;renamecolumns));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* add original filename;&lt;/P&gt;&lt;P&gt;data _test20;&lt;BR /&gt;set _test20;&lt;BR /&gt;bestandsnaam="&amp;amp;fname_loc";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;*add all;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data '||out||';&lt;BR /&gt;set '||out||' _test;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc delete data=_test; run;&lt;BR /&gt;');&lt;BR /&gt;run;&lt;BR /&gt;filename myfiles clear;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%multimp(dir=d:\excel,out=out_100)&lt;/P&gt;</description>
    <pubDate>Wed, 04 Mar 2020 09:24:52 GMT</pubDate>
    <dc:creator>GreyHamster</dc:creator>
    <dc:date>2020-03-04T09:24:52Z</dc:date>
    <item>
      <title>Using quotes in a macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629376#M186118</link>
      <description>&lt;P&gt;First: I am sorry for my displayname.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to import multiple excel files. So I wrote a program without macro language which works fine.&lt;/P&gt;&lt;P&gt;Now I need to change the variable names with spaces to one without.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the code below, which doesn't pass through the macro, probably because of all the quotes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;cats("'",cats(name),"'n","=",compress(name,"_","ADK")) as name1&lt;BR /&gt;/*%str(cats(%"%'%",cats(name),%"%'n%",%"=%",compress(name,%"_%",%"ADK%"))) as name1*/&lt;BR /&gt;into :renamecolumns separated by " "&lt;BR /&gt;from&lt;BR /&gt;dictionary.columns&lt;BR /&gt;where libname="WORK" and&lt;BR /&gt;memname="_TEST10"&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;renamecolumns;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Rename the variables */&lt;/P&gt;&lt;P&gt;data _TEST20;&lt;BR /&gt;set _TEST10 (rename=(&amp;amp;renamecolumns));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I change:&lt;/P&gt;&lt;P&gt;cats("'",cats(name),"'n","=",compress(name,"_","ADK")) as name1&lt;/P&gt;&lt;P&gt;so that it passes through in a macro program?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 08:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629376#M186118</guid>
      <dc:creator>GreyHamster</dc:creator>
      <dc:date>2020-03-04T08:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using quotes in a macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629377#M186119</link>
      <description>&lt;P&gt;What parts of this code need to be dynamic?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 08:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629377#M186119</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-04T08:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using quotes in a macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629379#M186120</link>
      <description>&lt;P&gt;It is for multiple excel files, the code isn't dynamic yet, I am just in the process of getting it right.&lt;/P&gt;&lt;P&gt;So it is not really about converting dataset names in macro values, but more about how to pass the expression through a macro to rename the variables.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 08:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629379#M186120</guid>
      <dc:creator>GreyHamster</dc:creator>
      <dc:date>2020-03-04T08:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using quotes in a macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629380#M186121</link>
      <description>&lt;P&gt;If you don't have anything that needs to be made dynamic, there is no need for a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I repeat my question: what parts of this code need to be made dynamic?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 08:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629380#M186121</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-04T08:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using quotes in a macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629385#M186123</link>
      <description>&lt;P&gt;Here is the whole macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options validvarname=any;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro MultImp(dir=,out=);&lt;/P&gt;&lt;P&gt;* dir of filenames;&lt;BR /&gt;%let flnm=%str(%'dir %")&amp;amp;dir.%str(\%" /A-D/B/ON%');&lt;BR /&gt;filename myfiles pipe %unquote(&amp;amp;flnm);&lt;/P&gt;&lt;P&gt;* list of filenames;&lt;BR /&gt;data list;&lt;BR /&gt;length fname $256.;&lt;BR /&gt;infile myfiles truncover;&lt;BR /&gt;input myfiles $100.;&lt;/P&gt;&lt;P&gt;fname=quote(upcase(cats("&amp;amp;dir",'\',myfiles)));&lt;/P&gt;&lt;P&gt;call symput('fname_loc',cats("_","&amp;amp;dir",'\',myfiles));&lt;BR /&gt;out="&amp;amp;out";&lt;BR /&gt;drop myfiles;&lt;/P&gt;&lt;P&gt;* import this range through the list of filenames;&lt;/P&gt;&lt;P&gt;call execute('&lt;BR /&gt;* import excels;&lt;/P&gt;&lt;P&gt;proc import dbms=xlsx out=_test10&lt;BR /&gt;datafile= '||fname||' replace ;&lt;BR /&gt;range="Sheet1$A5:BE2000";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;* varnames without spaces or special chars;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;cats("'",cats(name),"'n","=",compress(name,"_","ADK")) as name1&lt;BR /&gt;/*%str(cats(%"%'%",cats(name),%"%'n%",%"=%",compress(name,%"_%",%"ADK%"))) as name1*/&lt;BR /&gt;into :renamecolumns separated by " "&lt;BR /&gt;from&lt;BR /&gt;dictionary.columns&lt;BR /&gt;where libname="WORK" and&lt;BR /&gt;memname="_TEST10"&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;renamecolumns;&lt;/P&gt;&lt;P&gt;/* Rename the variables */&lt;BR /&gt;data _TEST20;&lt;BR /&gt;set _TEST10 (rename=(&amp;amp;renamecolumns));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* add original filename;&lt;/P&gt;&lt;P&gt;data _test20;&lt;BR /&gt;set _test20;&lt;BR /&gt;bestandsnaam="&amp;amp;fname_loc";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;*add all;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data '||out||';&lt;BR /&gt;set '||out||' _test;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc delete data=_test; run;&lt;BR /&gt;');&lt;BR /&gt;run;&lt;BR /&gt;filename myfiles clear;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%multimp(dir=d:\excel,out=out_100)&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 09:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629385#M186123</guid>
      <dc:creator>GreyHamster</dc:creator>
      <dc:date>2020-03-04T09:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using quotes in a macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629390#M186126</link>
      <description>&lt;P&gt;I would create a macro that runs the import and rename for a single Excel file:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro imp_rename(fname=,outdata=);
proc import dbms=xlsx out=_TEMP
datafile= "&amp;amp;fname" replace ;
range="Sheet1$A5:BE2000";
run;

proc sql;
select
cats("'",cats(name),"'n","=",compress(name,"_","ADK")) as name1
into :renamecolumns separated by " "
from
dictionary.columns
where libname="WORK" and
memname=upcase("_TEMP")
;
quit;

data &amp;amp;outdata;
set _TEMP;
rename &amp;amp;renamecolumns;
bestandsnaam = "&amp;amp;fname";
run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can call that macro repeatedly for a list of file and dataset names:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;

%macro MultImp(dir=,out=);

%let flnm=%str(%'dir %")&amp;amp;dir.%str(\%" /A-D/B/ON%');
filename myfiles pipe %unquote(&amp;amp;flnm);

* list of filenames;
data list;
length fname $256.;
retain counter 0;
infile myfiles truncover end=done;
input myfiles $100.;
fname=quote(upcase(cats("&amp;amp;dir",'\',myfiles)));
counter + 1;
call execute(cats('%nrstr(%imp_rename(fname=',fname,',outdata=_temp',put(counter,z3.),'))'));
if done then do;
  call execute("data &amp;amp;out; set";
  do i = 1 to counter;
    call execute(' _temp' !! put(i,z3.));
  end;
  call execute(';run;');
end;
run;

%mend;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Mar 2020 09:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629390#M186126</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-04T09:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using quotes in a macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629458#M186147</link>
      <description>Thanks for the solution, it worked with a little bit of tweaking. It looks a lot cleaner as well.&lt;BR /&gt;&lt;BR /&gt;This line misses a parenthesis: call execute("data &amp;amp;out; set";&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Mar 2020 15:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-quotes-in-a-macro-program/m-p/629458#M186147</guid>
      <dc:creator>GreyHamster</dc:creator>
      <dc:date>2020-03-04T15:35:18Z</dc:date>
    </item>
  </channel>
</rss>

