<?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 issue invoking macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/issue-invoking-macro/m-p/892640#M352569</link>
    <description>&lt;P&gt;I'm using the following macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option mprint symbolgen;
%macro ex(dsin,dsout);
%local i keynames keep_list rename_list;
%let keynames=Cname Country ISO ID Status Form Type Code Filing
	NACE NAICS SIC;
%do i=2008 %to 2022;
proc contents data=&amp;amp;dsin out=list(keep=name) noprint; run;
proc sql noprint; select nliteral(name), catx('=', nliteral(name), substr(name, 1, length(name)-5)) into
	:keep_list separated by ' ', :rename_list separated by ' ' from list where upcase(trim(name)) like "%_&amp;amp;i"; quit;
data b_&amp;amp;i; set &amp;amp;dsin(keep=&amp;amp;keynames &amp;amp;keep_list); %if (&amp;amp;sqlobs) %then %do; rename &amp;amp;rename_list; %end run;
%end;
data &amp;amp;dsout; set b_2008-b_2022; run;
%mend;

proc import datafile="/data/Export_us.xlsx" out=us dbms=xlsx replace;
%ex(us,o_us);

proc import datafile="/data/Export_dc.xlsx" out=dc dbms=xlsx replace;
%ex(dc,o_dc);

option nomprint nosymbolgen;
*end of macro;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My problem is that both o_us and o_dc (the output files) are the same. Any idea why this is happening?&lt;/P&gt;</description>
    <pubDate>Mon, 04 Sep 2023 22:19:34 GMT</pubDate>
    <dc:creator>Satori</dc:creator>
    <dc:date>2023-09-04T22:19:34Z</dc:date>
    <item>
      <title>issue invoking macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-invoking-macro/m-p/892640#M352569</link>
      <description>&lt;P&gt;I'm using the following macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option mprint symbolgen;
%macro ex(dsin,dsout);
%local i keynames keep_list rename_list;
%let keynames=Cname Country ISO ID Status Form Type Code Filing
	NACE NAICS SIC;
%do i=2008 %to 2022;
proc contents data=&amp;amp;dsin out=list(keep=name) noprint; run;
proc sql noprint; select nliteral(name), catx('=', nliteral(name), substr(name, 1, length(name)-5)) into
	:keep_list separated by ' ', :rename_list separated by ' ' from list where upcase(trim(name)) like "%_&amp;amp;i"; quit;
data b_&amp;amp;i; set &amp;amp;dsin(keep=&amp;amp;keynames &amp;amp;keep_list); %if (&amp;amp;sqlobs) %then %do; rename &amp;amp;rename_list; %end run;
%end;
data &amp;amp;dsout; set b_2008-b_2022; run;
%mend;

proc import datafile="/data/Export_us.xlsx" out=us dbms=xlsx replace;
%ex(us,o_us);

proc import datafile="/data/Export_dc.xlsx" out=dc dbms=xlsx replace;
%ex(dc,o_dc);

option nomprint nosymbolgen;
*end of macro;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My problem is that both o_us and o_dc (the output files) are the same. Any idea why this is happening?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 22:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-invoking-macro/m-p/892640#M352569</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-09-04T22:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: issue invoking macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-invoking-macro/m-p/892648#M352573</link>
      <description>&lt;P&gt;Can you show the log from running this code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I had to guess, this clause:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where upcase(trim(name)) like "%_&amp;amp;i"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Might be returning 0 obs, which would mean the macro variable RENAMELIST will be empty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you show the log, from running the code with MPRINT and SYMBOLGEN turned on, it should be easier to tell what's happening.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you just transposing this data from wide (with lots of variables like x_2001 y_2001 x_2002 y_2002 to long?&amp;nbsp; If so, you might want to look into use PROC TRANPOSE, or transposing it using a singe DATA step with arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 22:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-invoking-macro/m-p/892648#M352573</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-09-04T22:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: issue invoking macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-invoking-macro/m-p/892658#M352580</link>
      <description>&lt;P&gt;What do you get when you turn on MPRINT?&amp;nbsp; Not sure that SYMBOLGEN is going to help with debugging in this case, it will just clutter the SAS LOG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might help to clean up the formatting (perhaps posting into the forum has removed some of the white space?).&lt;/P&gt;
&lt;P&gt;That made it easier to notice that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) The the PROC CONTENTS should be before the %DO loop.&lt;/P&gt;
&lt;P&gt;2) The second %END is missing the ending semicolon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to check for literal _ character in the end of the variable names? If so you need to use and escape character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ex(dsin,dsout);
%local i keynames keep_list rename_list;
%let keynames=Cname Country ISO ID Status Form Type Code Filing
	NACE NAICS SIC
;
proc contents data=&amp;amp;dsin out=list(keep=name) noprint; run;
%do i=2008 %to 2022;
proc sql noprint;
select nliteral(name)
     , catx('=', nliteral(name), substr(name, 1, length(name)-5))
  into :keep_list separated by ' '
     , :rename_list separated by ' ' 
  from list 
  where upcase(trim(name)) like "%^_&amp;amp;i" escape '^'
; 
quit;
data b_&amp;amp;i;
  set &amp;amp;dsin(keep=&amp;amp;keynames &amp;amp;keep_list);
  %if (&amp;amp;sqlobs) %then %do;
  rename &amp;amp;rename_list; 
  %end;
run;
%end;
data &amp;amp;dsout; 
  set b_2008-b_2022; 
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 00:23:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-invoking-macro/m-p/892658#M352580</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-05T00:23:25Z</dc:date>
    </item>
  </channel>
</rss>

