<?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: Run a piece of code over different tables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Run-a-piece-of-code-over-different-tables/m-p/984715#M43726</link>
    <description>&lt;P&gt;Wrap it in a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro change_it(tabname);
data &amp;amp;tabname. (drop=value myperc_ label2);
set &amp;amp;tabname._;
mycount = input(scan(value , 1, ' ('), best.);
myperc_ = scan(value , 2, '()');
perc = compress(myperc_ , ' %');
label = label2;
run;
%mend;

%change_it(tab3) /* and so on */&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 12 Mar 2026 22:29:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2026-03-12T22:29:54Z</dc:date>
    <item>
      <title>Run a piece of code over different tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Run-a-piece-of-code-over-different-tables/m-p/984670#M43725</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   data Tab3 (drop=value myperc_ label2);
	  set Tab3_;
	    mycount = input(scan(value , 1, ' ('), best.);
	    myperc_ = scan(value , 2, '()');
	    perc = compress(myperc_ , ' %');
	    label = label2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With these few lines of code I split value from [N(%)] to [N], [%] as two different variables instead of one.&lt;/P&gt;
&lt;DIV&gt;I have to do this for 30 tables that are generated by a macro I cannot modify because of company policies. Is there a way to perform this task once across multiple tables, rather than editing each table individually?&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;One note: the output tables are stored in my working dir.&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2026 17:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Run-a-piece-of-code-over-different-tables/m-p/984670#M43725</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2026-03-12T17:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Run a piece of code over different tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Run-a-piece-of-code-over-different-tables/m-p/984715#M43726</link>
      <description>&lt;P&gt;Wrap it in a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro change_it(tabname);
data &amp;amp;tabname. (drop=value myperc_ label2);
set &amp;amp;tabname._;
mycount = input(scan(value , 1, ' ('), best.);
myperc_ = scan(value , 2, '()');
perc = compress(myperc_ , ' %');
label = label2;
run;
%mend;

%change_it(tab3) /* and so on */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Mar 2026 22:29:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Run-a-piece-of-code-over-different-tables/m-p/984715#M43726</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2026-03-12T22:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: Run a piece of code over different tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Run-a-piece-of-code-over-different-tables/m-p/984718#M43727</link>
      <description>&lt;P&gt;Alternative for a macro.&lt;/P&gt;
&lt;P&gt;Dynamically write a program (tt) that contains all the datasteps you need. Then submit this program with %INCLUDE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET ListDatasets=AA BB CC DD EE FF GG HH;

filename tt temp;

data _NULL_;
 file tt;
 i=1;
 do while ( scan("&amp;amp;ListDatasets",i," ") ne " " );
  currds=trim(left(upcase(scan("&amp;amp;ListDatasets",i," "))));

   put "data " currds "(drop=value myperc_ label2);    ";
   put " set " currds +(-1) "_;                        ";
   put " mycount = input(scan(value , 1, ' ('), best.);";
   put " myperc_ = scan(value , 2, '()');              ";
   put " perc = compress(myperc_ , ' %');              ";
   put " label = label2;                               ";
   put "run;                                           ";

  i=i+1;
 end;
run;

%INCLUDE tt / source2;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BR, Koen&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2026 23:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Run-a-piece-of-code-over-different-tables/m-p/984718#M43727</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2026-03-12T23:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Run a piece of code over different tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Run-a-piece-of-code-over-different-tables/m-p/984720#M43728</link>
      <description>&lt;P&gt;Do the datasets all have the same structure? Do you want to output one single dataset that contains the observations from all of the datasets?&amp;nbsp; Or do you need to keep them separate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know the names of the datasets?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not then how will you get the names?&amp;nbsp; Do you need to run this step on every dataset that has the variable VALUE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a reason you are leaving PERC as character but converting N to a number?&lt;/P&gt;
&lt;P&gt;Is there another variable with the overall N that you could use to re-calculate PERC instead of just reading in the rounded value that was written into the character variable VALUE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE:&amp;nbsp; BEST is the name of a FORMAT.&amp;nbsp; Your code works because SAS treats BEST when used as an INFORMAT as an alias for the normal numeric informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2026 03:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Run-a-piece-of-code-over-different-tables/m-p/984720#M43728</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-03-13T03:12:05Z</dc:date>
    </item>
  </channel>
</rss>

