<?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: how to use macro variable in proc sql select into in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886268#M350223</link>
    <description>&lt;P&gt;You don't need to specify the ending of a list when creating macro variables with SQL.&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
select distinct b into : grp1 -  
from B;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This will create the number of macro variables required automatically.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select distinct age into :age1-
from sashelp.class;
quit;

%put &amp;amp;sqlobs;

*if you need it for future loops;
%let nobs = &amp;amp;sqlobs;

*check macro variables created;
%put &amp;amp;age1.;

*age6 = 16;
%put &amp;amp;&amp;amp;age&amp;amp;sqlobs.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Jul 2023 16:56:28 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-07-25T16:56:28Z</dc:date>
    <item>
      <title>how to use macro variable in proc sql select into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886243#M350212</link>
      <description>&lt;P&gt;I created a macro variable &amp;amp;count which equals 3 in this case, and want to use it in another proc sql, but it is not working, please suggest, thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select count(distinct a) into: count from A;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%global &amp;amp;count.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select distinct b into : grp1 - :grp&amp;amp;count. from B;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 14:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886243#M350212</guid>
      <dc:creator>kc_sas</dc:creator>
      <dc:date>2023-07-25T14:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro variable in proc sql select into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886246#M350213</link>
      <description>&lt;P&gt;Never mind, I have figured it out, need to remove the lead space in &amp;amp;count&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select left(put(count(distinct a), 8.)) into: count from A;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select distinct b into : grp1 - :grp&amp;amp;count. from B;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 14:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886246#M350213</guid>
      <dc:creator>kc_sas</dc:creator>
      <dc:date>2023-07-25T14:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro variable in proc sql select into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886247#M350214</link>
      <description>What is the intended outcome of the latter sql ?&lt;BR /&gt;--fja</description>
      <pubDate>Tue, 25 Jul 2023 14:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886247#M350214</guid>
      <dc:creator>fja</dc:creator>
      <dc:date>2023-07-25T14:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro variable in proc sql select into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886248#M350215</link>
      <description>&lt;P&gt;the outcome in this case would be:&lt;/P&gt;&lt;P&gt;&amp;amp;grp1 = b1&lt;/P&gt;&lt;P&gt;&amp;amp;grp2 = b2&lt;/P&gt;&lt;P&gt;&amp;amp;grp3 = b3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;because the value of &amp;amp;count is changing, so need to do it in a robust way&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 14:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886248#M350215</guid>
      <dc:creator>kc_sas</dc:creator>
      <dc:date>2023-07-25T14:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro variable in proc sql select into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886255#M350217</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439379"&gt;@kc_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;the outcome in this case would be:&lt;/P&gt;
&lt;P&gt;&amp;amp;grp1 = b1&lt;/P&gt;
&lt;P&gt;&amp;amp;grp2 = b2&lt;/P&gt;
&lt;P&gt;&amp;amp;grp3 = b3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;because the value of &amp;amp;count is changing, so need to do it in a robust way&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are working WAY TOO HARD and making SQL work too hard also.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let SQL do the counting for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct b
  into :grp1 - 
  from B
;
%let count=&amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jul 2023 15:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886255#M350217</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-25T15:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro variable in proc sql select into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886266#M350222</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439379"&gt;@kc_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Never mind, I have figured it out, need to remove the lead space in &amp;amp;count&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;select left(put(count(distinct a), 8.)) into: count from A;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql noprint;&lt;/P&gt;
&lt;P&gt;select distinct b into : grp1 - :grp&amp;amp;count. from B;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Congratulations on figuring this out. Note: any conversion of numeric to character, and all macro variables are character, means you have to take control of the conversion or get results that may not work as intended.&lt;/P&gt;
&lt;P&gt;Alternatively use the -L option with the Put function to left justify output.&lt;/P&gt;
&lt;PRE&gt;put (variable, format. -L) &lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jul 2023 16:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886266#M350222</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-25T16:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro variable in proc sql select into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886268#M350223</link>
      <description>&lt;P&gt;You don't need to specify the ending of a list when creating macro variables with SQL.&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
select distinct b into : grp1 -  
from B;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This will create the number of macro variables required automatically.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select distinct age into :age1-
from sashelp.class;
quit;

%put &amp;amp;sqlobs;

*if you need it for future loops;
%let nobs = &amp;amp;sqlobs;

*check macro variables created;
%put &amp;amp;age1.;

*age6 = 16;
%put &amp;amp;&amp;amp;age&amp;amp;sqlobs.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jul 2023 16:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-proc-sql-select-into/m-p/886268#M350223</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-25T16:56:28Z</dc:date>
    </item>
  </channel>
</rss>

