<?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: Proc SQL into macro variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35673#M8835</link>
    <description>&amp;gt; Patrick;&lt;BR /&gt;
&amp;gt; I am going to point this out because I have seen this&lt;BR /&gt;
&amp;gt; in several macros at my current location, and it&lt;BR /&gt;
&amp;gt; drives me nuts.&lt;BR /&gt;
&lt;BR /&gt;
I would be equally concerned about any macro/program that uses this "macro array" technique.  Why would anyone want to take perfectly good data from a data set and put it into a macro array or TWO arrays as in this example?  I guess the next question how to put ALL data set variables into macro arrays. &lt;BR /&gt;
&lt;BR /&gt;
Macro arrays are useless.  If you're putting that much data into macro variables you need to rewrite the program.</description>
    <pubDate>Fri, 18 Jun 2010 17:13:26 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2010-06-18T17:13:26Z</dc:date>
    <item>
      <title>Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35664#M8826</link>
      <description>I have a dataset with 10 observations which has only 2 variables, division and manager.&lt;BR /&gt;
&lt;BR /&gt;
I would like to create macro variable &amp;amp;division1 through &amp;amp;division10 and &amp;amp;manager1 through &amp;amp;manager10, such that &amp;amp;division1 and &amp;amp;manager1 come from the same row.&lt;BR /&gt;
&lt;BR /&gt;
The following code generates the division macros variables correctly, however the manager macro variables are not the correct ones.&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL noprint;&lt;BR /&gt;
       select count (distinct division) into :n from delivery_division_info;&lt;BR /&gt;
       select distinct division           into :division1 through :division%left(&amp;amp;n)&lt;BR /&gt;
                                                         from delivery_division_info;&lt;BR /&gt;
       select distinct manager         into :manager1 through :manager%left(&amp;amp;n)&lt;BR /&gt;
                                                         from delivery_division_info;&lt;BR /&gt;
              quit;</description>
      <pubDate>Mon, 14 Jun 2010 21:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35664#M8826</guid>
      <dc:creator>steve_citi</dc:creator>
      <dc:date>2010-06-14T21:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35665#M8827</link>
      <description>Hi:&lt;BR /&gt;
    In this program, I want to get every student from SASHELP.CLASS and their age into numbered macro variables. If I don't have AGE on the same SELECT as NAME, there's no guarantee that the names and ages will "match up" -- they might get selected the same way both times, but they might not. The SELECT statement can be optimized to get data and with 2 separate SELECTs, you -could- potentially get the 2 queries returned in 2 different orders. Also, if you do a "select distinct manager", what happens if you have 1 manager for 2 departments?? He or she will show up in the macro variables only 1 time, but don't you want him or her to be in the macro variables twice -- one time for each department row???&lt;BR /&gt;
&lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods listing;&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
  select count (name) into :n from sashelp.class;&lt;BR /&gt;
  select name, age into :name1 through :name%left(&amp;amp;n),&lt;BR /&gt;
                        :age1 through :age%left(&amp;amp;n)&lt;BR /&gt;
  from sashelp.class;&lt;BR /&gt;
quit; &lt;BR /&gt;
                          &lt;BR /&gt;
** partial display of macro variable values;&lt;BR /&gt;
%put count= &amp;amp;n;&lt;BR /&gt;
%put name1 and age1 = &amp;amp;name1 &amp;amp;age1;&lt;BR /&gt;
%put name2 and age2 = &amp;amp;name2 &amp;amp;age2;&lt;BR /&gt;
%put name3 and age3 = &amp;amp;name3 &amp;amp;age3;&lt;BR /&gt;
%put name4 and age4 = &amp;amp;name4 &amp;amp;age4;&lt;BR /&gt;
%put name5 and age5 = &amp;amp;name5 &amp;amp;age5;&lt;BR /&gt;
%put name6 and age6 = &amp;amp;name6 &amp;amp;age6;&lt;BR /&gt;
%put name7 and age7 = &amp;amp;name7 &amp;amp;age7;&lt;BR /&gt;
%put name8 and age8 = &amp;amp;name8 &amp;amp;age8;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 14 Jun 2010 21:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35665#M8827</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-06-14T21:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35666#M8828</link>
      <description>Hi,Steve,&lt;BR /&gt;
&lt;BR /&gt;
if your sas is running on Windows, you can use automatic macro variable SYSMaxLong to create mvars without knowing how many observations in your dataset.&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select sex,age into&lt;BR /&gt;
  :sex1-:sex&amp;amp;SYSMAXLONG ,:age1-:age&amp;amp;SYSMAXLONG &lt;BR /&gt;
 from sashelp.class;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%put _user_;&lt;BR /&gt;
&lt;BR /&gt;
in this case, you will see 19 sex mvars and age mvars in the log.&lt;BR /&gt;
&lt;BR /&gt;
HTH</description>
      <pubDate>Tue, 15 Jun 2010 03:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35666#M8828</guid>
      <dc:creator>AUTigers</dc:creator>
      <dc:date>2010-06-15T03:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35667#M8829</link>
      <description>Hi. There is a auto macro variable (&amp;amp;sqlobs) created by proc sql , you can use it.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select division,manager&lt;BR /&gt;
     into :division1 - :division&amp;amp;sqlobs , :manager1 - :manager&amp;amp;sqlobs&lt;BR /&gt;
  from delivery_division_info;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 15 Jun 2010 06:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35667#M8829</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-06-15T06:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35668#M8830</link>
      <description>&amp;gt; Hi. There is a auto macro variable (&amp;amp;sqlobs) created&lt;BR /&gt;
&amp;gt; by proc sql , you can use it.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; [pre]&lt;BR /&gt;
&amp;gt; proc sql;&lt;BR /&gt;
&amp;gt;   select division,manager&lt;BR /&gt;
&amp;gt; into :division1 - :division&amp;amp;sqlobs , :manager1 -&lt;BR /&gt;
&amp;gt;  :manager&amp;amp;sqlobs&lt;BR /&gt;
&amp;gt;  from delivery_division_info;&lt;BR /&gt;
&amp;gt; [/pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Ksharp&lt;BR /&gt;
&lt;BR /&gt;
have you tried this?&lt;BR /&gt;
It gives me these warnings[pre]WARNING: INTO Clause :division1 through :division0 does not specify a valid sequence of macro variables.&lt;BR /&gt;
WARNING: INTO Clause :manager1 through :manager0 does not specify a valid sequence of macro variables.[/pre]&lt;BR /&gt;
Normally I would just use a large number (I really don't want a really large number of macro variables), so I just use 9999 or even 999, in[pre]proc sql;&lt;BR /&gt;
   select division,manager&lt;BR /&gt;
     into :division1 - :division999&lt;BR /&gt;
        , :manager1 - :manager999&lt;BR /&gt;
     from delivery_division_info ;&lt;BR /&gt;
quit ;[/pre]</description>
      <pubDate>Tue, 15 Jun 2010 15:46:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35668#M8830</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-06-15T15:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35669#M8831</link>
      <description>Hi. Peter you are right .It should have a same sql statement ahead.&lt;BR /&gt;
try this.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
options symbolgen;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 select name&lt;BR /&gt;
   from sashelp.class;&lt;BR /&gt;
&lt;BR /&gt;
 select name&lt;BR /&gt;
   into :name1 - :name&amp;amp;sqlobs&lt;BR /&gt;
   from sashelp.class;&lt;BR /&gt;
quit;&lt;BR /&gt;
%put &amp;amp;name1 &amp;amp;name2 &amp;amp;&amp;amp;name&amp;amp;sqlobs.;&lt;BR /&gt;
%put _user_;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 16 Jun 2010 07:40:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35669#M8831</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-06-16T07:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35670#M8832</link>
      <description>Or instead of Proc SQL a datastep with only one pass through the data:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set sashelp.class nobs=nobs;&lt;BR /&gt;
  if _n_=1 then call symput('N_pairs',cats(nobs));&lt;BR /&gt;
  call symput(cats('name',_n_),cats(Name));&lt;BR /&gt;
  call symput(cats('Age',_n_),cats(Age));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%macro listvars;&lt;BR /&gt;
  %do i=1 %to &amp;amp;N_pairs;&lt;BR /&gt;
    %put;&lt;BR /&gt;
    %put name&amp;amp;i= &amp;amp;&amp;amp;&amp;amp;name&amp;amp;i;&lt;BR /&gt;
    %put age&amp;amp;i= &amp;amp;&amp;amp;&amp;amp;age&amp;amp;i;&lt;BR /&gt;
  %end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%listvars</description>
      <pubDate>Wed, 16 Jun 2010 08:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35670#M8832</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-06-16T08:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35671#M8833</link>
      <description>Patrick;&lt;BR /&gt;
I am going to point this out because I have seen this in several macros at my current location, and it drives me nuts.&lt;BR /&gt;
&lt;BR /&gt;
%put name&amp;amp;i= &amp;amp;&amp;amp;&amp;amp;name&amp;amp;i;  will work only if you are aware of everything in your current environment. It should be &lt;BR /&gt;
%put name&amp;amp;i= &amp;amp;&amp;amp;name&amp;amp;i;&lt;BR /&gt;
&lt;BR /&gt;
Why;&lt;BR /&gt;
&amp;amp;&amp;amp; -- resolves to &amp;amp;&lt;BR /&gt;
&amp;amp;name -- if it has not been assigned (and you are assuming it has not) it resolves to "name" inside a complex macro variable  like this.  If there was a global macro variable set it resolves to that.&lt;BR /&gt;
&amp;amp;i -- resolves to your counter.&lt;BR /&gt;
&lt;BR /&gt;
So if somewhere in your job stream there is a %let name = fred,  your log will state "&amp;amp;fred1 not resolved". &lt;BR /&gt;
&lt;BR /&gt;
If you are making macros available to others, this can cause problems.</description>
      <pubDate>Wed, 16 Jun 2010 12:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35671#M8833</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-06-16T12:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35672#M8834</link>
      <description>Flip&lt;BR /&gt;
&lt;BR /&gt;
You're of course right - and I must have been tired....&lt;BR /&gt;
&lt;BR /&gt;
Cheers&lt;BR /&gt;
Patrick</description>
      <pubDate>Fri, 18 Jun 2010 13:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35672#M8834</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-06-18T13:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35673#M8835</link>
      <description>&amp;gt; Patrick;&lt;BR /&gt;
&amp;gt; I am going to point this out because I have seen this&lt;BR /&gt;
&amp;gt; in several macros at my current location, and it&lt;BR /&gt;
&amp;gt; drives me nuts.&lt;BR /&gt;
&lt;BR /&gt;
I would be equally concerned about any macro/program that uses this "macro array" technique.  Why would anyone want to take perfectly good data from a data set and put it into a macro array or TWO arrays as in this example?  I guess the next question how to put ALL data set variables into macro arrays. &lt;BR /&gt;
&lt;BR /&gt;
Macro arrays are useless.  If you're putting that much data into macro variables you need to rewrite the program.</description>
      <pubDate>Fri, 18 Jun 2010 17:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35673#M8835</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-06-18T17:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL into macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35674#M8836</link>
      <description>how about another approach (than rewriting) &lt;BR /&gt;
how about more training</description>
      <pubDate>Fri, 18 Jun 2010 19:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-into-macro-variables/m-p/35674#M8836</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-06-18T19:20:01Z</dc:date>
    </item>
  </channel>
</rss>

