<?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: Name a table after a compressed macro variable value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867862#M342772</link>
    <description>&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068&lt;/A&gt;</description>
    <pubDate>Mon, 03 Apr 2023 20:50:16 GMT</pubDate>
    <dc:creator>zcoop</dc:creator>
    <dc:date>2023-04-03T20:50:16Z</dc:date>
    <item>
      <title>Name a table after a compressed macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867848#M342760</link>
      <description>&lt;P&gt;I feel very close to solving this issue on my own... My guess is it has to do with mismatching variable types?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get my code to produce two tables called 'recentAB' and 'recentAC'. (In actual practice, my programlist will be much, much longer, but all substrings of it will have hyphens that I want to not appear in the titles of the datasets.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let programlist = A-B A-C;

%macro testloop;
%local i ithprogram nodash;
proc sql;
	%do i = 1 %to %sysfunc(countw(&amp;amp;programlist, ' '));
		%let ithprogram = %scan(&amp;amp;programlist, &amp;amp;i, ' ');
&lt;FONT color="#339966"&gt;		%let nodash = compress(&amp;amp;ithprogram, '-');
		create table recent_&amp;amp;nodash as&lt;/FONT&gt;
		select distinct t1.id,
			t1.yeardate,
			t1.program,
		from libraryname.dataset t1
		where t1.yeardate &amp;gt;= "2018" and t1.program = "&amp;amp;ithprogram"
		order by t1.yeardate,
			t1.id;
	%end;
quit;
%mend;
%testloop;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I colored the text (in green) where I'm pretty sure my error is occurring. If I were to replace that part with&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;create table recent&amp;amp;i as&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then the tables 'recent1' and 'recent2' get created (with their contents correctly filtered)... So I'm not sure why recent&amp;amp;i works when recent&amp;amp;nodash does not?&lt;/P&gt;&lt;P&gt;Reason I think it is a type mismatch is that I get ERROR 22-322 when I try running my code.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 19:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867848#M342760</guid>
      <dc:creator>zcoop</dc:creator>
      <dc:date>2023-04-03T19:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Name a table after a compressed macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867851#M342763</link>
      <description>&lt;P&gt;You are close.&amp;nbsp; Instead of giving you a solution, I'd suggest you play around with debugging a simpler version, with some %PUT statements added to see the values of your macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro testloop(programlist=);
%local i ithprogram nodash;

%do i = 1 %to %sysfunc(countw(&amp;amp;programlist, ' '));
	%let ithprogram = %scan(&amp;amp;programlist, &amp;amp;i, ' ');
	%let nodash = compress(&amp;amp;ithprogram, '-');

	%put &amp;amp;=i &amp;amp;=ithprogram &amp;amp;=nodash  ;
%end;
%mend;
%testloop(programlist=A-B A-C)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Apr 2023 20:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867851#M342763</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-04-03T20:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: Name a table after a compressed macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867852#M342764</link>
      <description>&lt;P&gt;You cannot name a dataset&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;recent_compress(A-B, '-')&lt;/PRE&gt;
&lt;P&gt;Which is what your program is doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use a SAS function in macro code you need to use the %SYSFUNC() macro function to call the function.&amp;nbsp; And there is no need to try to compress the single quotes out of the value because the %SCAN() function results will not include them since you included single quotes in the set of values to use a delimiter characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let ithprogram = %scan(&amp;amp;programlist, &amp;amp;i, ' ');
%let nodash = %sysfunc(compress(&amp;amp;ithprogram,-));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 20:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867852#M342764</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-03T20:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Name a table after a compressed macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867853#M342765</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;&lt;FONT color="#339966"&gt;%let nodash = %sysfunc(compress(&amp;amp;ithprogram, _, KDA));&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it will left only letters digits and underscore(_) from your string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your current code produces:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;&lt;FONT color="#339966"&gt;compress(A-B, '-')&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as a value of nodash, you can see it adding:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;&lt;FONT color="#339966"&gt;%put &amp;amp;=nodash.;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before "create table".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use a function to process a macrovariable or proces something in macro language you need to put the function inside %sysfunc(), e.g.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let = %sysfunc(compbl(A     B)); /* returns `A B` (only 1 space) */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and since macro language has only text was values you don't need quotes. So in you code this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;%sysfunc(countw(&amp;amp;programlist, ' '))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt; %scan(&amp;amp;programlist, &amp;amp;i, ' ');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;%sysfunc(countw(&amp;amp;programlist, %str( )));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;%scan(&amp;amp;programlist, &amp;amp;i, %str( ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;sot the quotes won't be used in separators list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 20:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867853#M342765</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-04-03T20:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Name a table after a compressed macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867856#M342767</link>
      <description>Thank you all for the quick response!... I feel kind of silly for not noticing my lack of %sysfunc() on that line despite me trying to debug the dumb thing for about an hour.</description>
      <pubDate>Mon, 03 Apr 2023 20:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867856#M342767</guid>
      <dc:creator>zcoop</dc:creator>
      <dc:date>2023-04-03T20:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Name a table after a compressed macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867858#M342769</link>
      <description>&lt;P&gt;Remember Maxim 52! (&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068)" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 20:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867858#M342769</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-04-03T20:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: Name a table after a compressed macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867860#M342770</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zcoop_0-1680554751387.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82291iE7621A9FB3C730A8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="zcoop_0-1680554751387.png" alt="zcoop_0-1680554751387.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Looks like a bad url.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 20:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867860#M342770</guid>
      <dc:creator>zcoop</dc:creator>
      <dc:date>2023-04-03T20:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: Name a table after a compressed macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867862#M342772</link>
      <description>&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068&lt;/A&gt;</description>
      <pubDate>Mon, 03 Apr 2023 20:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867862#M342772</guid>
      <dc:creator>zcoop</dc:creator>
      <dc:date>2023-04-03T20:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Name a table after a compressed macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867871#M342778</link>
      <description>&lt;P&gt;it took the last ")" to the link...&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 21:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Name-a-table-after-a-compressed-macro-variable-value/m-p/867871#M342778</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-04-03T21:22:38Z</dc:date>
    </item>
  </channel>
</rss>

