<?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 Store multiple values from a variable in different macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853550#M337380</link>
    <description>&lt;P&gt;Hi Everybody&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to store multiple values containing datasets names for the use in a loop to import multiple sas files?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have imported an excel file containing two rows: "Table" and "Select". For those rows where select is equal to "X" I want to create a macro containing the name in the table row?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example dataset:&lt;/P&gt;&lt;P&gt;Table&amp;nbsp; &amp;nbsp;Select&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table1&amp;nbsp; &amp;nbsp;x&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table2&amp;nbsp; &amp;nbsp;x&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table3&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table4&amp;nbsp; &amp;nbsp;x&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create multiple macros containing the values "Table1", "Table2" and "Table3" for the use in a macro loop to import these three datafiles in SAS format&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;Frank&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jan 2023 19:20:57 GMT</pubDate>
    <dc:creator>Frank_johannes</dc:creator>
    <dc:date>2023-01-12T19:20:57Z</dc:date>
    <item>
      <title>Store multiple values from a variable in different macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853550#M337380</link>
      <description>&lt;P&gt;Hi Everybody&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to store multiple values containing datasets names for the use in a loop to import multiple sas files?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have imported an excel file containing two rows: "Table" and "Select". For those rows where select is equal to "X" I want to create a macro containing the name in the table row?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example dataset:&lt;/P&gt;&lt;P&gt;Table&amp;nbsp; &amp;nbsp;Select&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table1&amp;nbsp; &amp;nbsp;x&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table2&amp;nbsp; &amp;nbsp;x&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table3&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table4&amp;nbsp; &amp;nbsp;x&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create multiple macros containing the values "Table1", "Table2" and "Table3" for the use in a macro loop to import these three datafiles in SAS format&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;Frank&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 19:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853550#M337380</guid>
      <dc:creator>Frank_johannes</dc:creator>
      <dc:date>2023-01-12T19:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Store multiple values from a variable in different macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853557#M337383</link>
      <description>&lt;P&gt;You do not want macros. You want macro variables. These are not the same. Do not use the word "macro" to describe macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I want to create multiple macros containing the values "Table1", "Table2" and "Table3"&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;I assume you mean&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I want to create multiple macro variables containing the values Table1, Table2&amp;nbsp; and&amp;nbsp; Table4 (should have table 4 not table 3, with no quotes)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    set have end=eof;
    n=0;
    if select="X" then do;
        n+1;
        call symputx(cats('macrovar',n),table);
    end;
    if eof then call symputx('n',n);
run;

%put &amp;amp;=macrovar1;
%put &amp;amp;=macrovar2;
%put &amp;amp;=macrovar3;
%put &amp;amp;=n;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jan 2023 19:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853557#M337383</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-12T19:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Store multiple values from a variable in different macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853561#M337386</link>
      <description>&lt;P&gt;Why do you need to store the data into macro variables?&amp;nbsp; Why not just use the data to drive the code creation directly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set example;
  where SELECT='X' ;
  call execute( ..... code generated using the value of TABLE ... );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if you do need the list in macro variable why not just make ONE macro variable?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select table into :tablelist separated by ' '
from example
where select='X'
;
%let ntables=&amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really need to make multiple macro variable then use this SQL syntax.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select table into :table1-
from example
where select='X'
;
%let ntables=&amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jan 2023 19:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853561#M337386</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-12T19:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Store multiple values from a variable in different macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853567#M337388</link>
      <description>&lt;P&gt;Hi Paige,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply and corrections to this topic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My log says: WARNING: Apparent symbolic reference MACROVAR2 not resolved.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have typed:&lt;/P&gt;&lt;P&gt;proc import datafile= "&amp;amp;path\test.xlsx"&lt;BR /&gt;out= tables&lt;BR /&gt;dbms= xlsx&lt;BR /&gt;replace;&lt;BR /&gt;sheet= "Tables";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set tables end=eof;&lt;BR /&gt;n=0;&lt;BR /&gt;if select="x" then do;&lt;BR /&gt;n+1;&lt;BR /&gt;call symputx(cats('macrovar',n),table);&lt;BR /&gt;end;&lt;BR /&gt;if eof then call symputx('n',n);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%put &amp;amp;=macrovar1;&lt;BR /&gt;%put &amp;amp;=macrovar2;&lt;BR /&gt;%put &amp;amp;=macrovar;&lt;BR /&gt;%put &amp;amp;=n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I loop through the macro variables in a datastep afterwards?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Frank&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 20:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853567#M337388</guid>
      <dc:creator>Frank_johannes</dc:creator>
      <dc:date>2023-01-12T20:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Store multiple values from a variable in different macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853569#M337390</link>
      <description>&lt;P&gt;Macro variables will only be created for observations where the value of SELECT was a single lowercase x.&lt;/P&gt;
&lt;P&gt;If it had an uppercase X or a space character followed by a lowercase x then it would not be "selected".&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 20:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853569#M337390</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-12T20:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: Store multiple values from a variable in different macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853570#M337391</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
infile cards truncover;
input table $ select $;
cards;
one x
two x
three 
four x
five 
six x
;;;;;
run;

proc sql noprint;
select table into :table1- 
from example
where select = 'x';
quit;

options mprint;
%let numTables = &amp;amp;sqlobs;

%put &amp;amp;numTables;
%put &amp;amp;Table1.;
%put &amp;amp;Table2.;
%put &amp;amp;&amp;amp;table&amp;amp;numTables.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt; 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         data example;
 70         infile cards truncover;
 71         input table $ select $;
 72         cards;
 
 NOTE: The data set WORK.EXAMPLE has 6 observations and 2 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              523.31k
       OS Memory           20644.00k
       Timestamp           01/12/2023 08:22:38 PM
       Step Count                        59  Switch Count  2
       Page Faults                       0
       Page Reclaims                     131
       Page Swaps                        0
       Voluntary Context Switches        10
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 79         ;;;;;
 
 80         run;
 81         
 82         proc sql noprint;
 83         select table into :table1-
 84         from example
 85         where select = 'x';
 86         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              5456.81k
       OS Memory           25768.00k
       Timestamp           01/12/2023 08:22:38 PM
       Step Count                        60  Switch Count  0
       Page Faults                       0
       Page Reclaims                     72
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           0
       
 
 87         
 88         options mprint;
 89         %let numTables = &amp;amp;sqlobs;
 90         
 91         %put &amp;amp;numTables;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt; 4&lt;/STRONG&gt;&lt;/FONT&gt;
 92         %put &amp;amp;Table1.;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt; one&lt;/STRONG&gt;&lt;/FONT&gt;
 93         %put &amp;amp;Table2.;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt; two&lt;/STRONG&gt;
&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt; 94         %put &amp;amp;&amp;amp;table&amp;amp;numTables.;&lt;/FONT&gt;
 six&lt;/STRONG&gt;&lt;/FONT&gt;
 95         
 96         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 106        &lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/424788"&gt;@Frank_johannes&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Everybody&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to store multiple values containing datasets names for the use in a loop to import multiple sas files?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have imported an excel file containing two rows: "Table" and "Select". For those rows where select is equal to "X" I want to create a macro containing the name in the table row?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example dataset:&lt;/P&gt;
&lt;P&gt;Table&amp;nbsp; &amp;nbsp;Select&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table1&amp;nbsp; &amp;nbsp;x&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table2&amp;nbsp; &amp;nbsp;x&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table3&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table4&amp;nbsp; &amp;nbsp;x&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create multiple macros containing the values "Table1", "Table2" and "Table3" for the use in a macro loop to import these three datafiles in SAS format&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Frank&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 20:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853570#M337391</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-12T20:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Store multiple values from a variable in different macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853578#M337392</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/424788"&gt;@Frank_johannes&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Paige,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your reply and corrections to this topic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My log says: WARNING: Apparent symbolic reference MACROVAR2 not resolved.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have typed:&lt;/P&gt;
&lt;P&gt;proc import datafile= "&amp;amp;path\test.xlsx"&lt;BR /&gt;out= tables&lt;BR /&gt;dbms= xlsx&lt;BR /&gt;replace;&lt;BR /&gt;sheet= "Tables";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set tables end=eof;&lt;BR /&gt;n=0;&lt;BR /&gt;if select="x" then do;&lt;BR /&gt;n+1;&lt;BR /&gt;call symputx(cats('macrovar',n),table);&lt;BR /&gt;end;&lt;BR /&gt;if eof then call symputx('n',n);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;=macrovar1;&lt;BR /&gt;%put &amp;amp;=macrovar2;&lt;BR /&gt;%put &amp;amp;=macrovar;&lt;BR /&gt;%put &amp;amp;=n;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I loop through the macro variables in a datastep afterwards?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;// Frank&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;My mistake, the IF statement should test for lower case x&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 21:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-multiple-values-from-a-variable-in-different-macros/m-p/853578#M337392</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-12T21:26:34Z</dc:date>
    </item>
  </channel>
</rss>

