<?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 does not work with multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977186#M378443</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442038"&gt;@PamG&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is a sample data. What I am trying to get at is that the order in which the variables are entered in PROC SQL when one of them is entered as INTO matters. Is there a way to get COUNT before SUM and assign COUNT to a macro variable in the same PROC SQL code?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First, as stated by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;we don't know your final goal here. That would be very helpful information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are only very rare cases where you need to put statistics like count and sum into a macro variable, and in fact there are better ways to determine these values than SQL. So I think the efficiency of what you are doing could improve, if only we knew what the final goal is.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Oct 2025 16:42:44 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2025-10-16T16:42:44Z</dc:date>
    <item>
      <title>PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977159#M378432</link>
      <description>&lt;P&gt;I would like to report counts with percentages in the next column after&amp;nbsp; the counts for several sepecific conditions.&amp;nbsp; The easiest way for me is to do with PROC SQL.&amp;nbsp; However the third line of code given the sample code does not work. I want to report percentages after counts, not the other way around.&amp;nbsp; It seems the order of variables matter when using INTO in SAS.&amp;nbsp; Is there a way around it without using multiple SELECT statements?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   
data one;
  do x=-2 to 2 by 0.01;
  y=(x-2)*(x-1.5)*(x-1)*(x-.5)*x*(x+.5)*(x+1)*(x+1.5)*(x+2);
  output;
  end;
  run;

  proc sql;
  select count(x),sum(x) into :a  from one; **works;
 select sum(x) into :a,count(x)  from one; **does not work;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Oct 2025 13:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977159#M378432</guid>
      <dc:creator>PamG</dc:creator>
      <dc:date>2025-10-16T13:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977161#M378433</link>
      <description>&lt;P&gt;I think you want this.&amp;nbsp; I would suggest data set is more useful.&amp;nbsp; You don't want to have to manage all that data in macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  do x=-2 to 2 by 0.01;
     y=(x-2)*(x-1.5)*(x-1)*(x-.5)*x*(x+.5)*(x+1)*(x+1.5)*(x+2);
     output;
     end;
  run;

proc sql;
   select count(x),sum(x) into :countx, :sumx  from one; **works;
   quit;
%put NOTE: &amp;amp;=countx &amp;amp;=sumx;

proc summary data=one;
   output out=summary n(x)=countx sum(x)=sumx;
   run;
proc print;
   run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;65         proc sql;
66            select count(x),sum(x) into :countx, :sumx  from one;
66       !                                                          **works;
67            quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      

68         %put NOTE: &amp;amp;=countx &amp;amp;=sumx;
NOTE: COUNTX=     401 SUMX=6.63E-13&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Oct 2025 14:02:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977161#M378433</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-10-16T14:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977163#M378434</link>
      <description>&lt;P&gt;You say you want a percentage. Percentage of what vs. what?&lt;/P&gt;
&lt;P&gt;Note that counts and sums let you calculate averages, not percentages.&lt;/P&gt;
&lt;P&gt;Please explain what you're after, &amp;nbsp;e.g. by posting a "want" dataset derived from your example dataset one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Oct 2025 14:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977163#M378434</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-10-16T14:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977168#M378435</link>
      <description>&lt;P&gt;This is a sample data. What I am trying to get at is that the order in which the variables are entered in PROC SQL when one of them is entered as INTO matters. Is there a way to get COUNT before SUM and assign COUNT to a macro variable in the same PROC SQL code?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Oct 2025 14:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977168#M378435</guid>
      <dc:creator>PamG</dc:creator>
      <dc:date>2025-10-16T14:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977171#M378438</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442038"&gt;@PamG&lt;/a&gt;&amp;nbsp;wrote:
&lt;P class="1760625075964"&gt;&amp;nbsp;&lt;/P&gt;
&lt;SPAN&gt;Is there a way to get COUNT before SUM and assign COUNT to a macro variable in the same PROC SQL code?&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;has already answered that. But I have a strong inkling that your final goal can be achieved without the macro detour.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Oct 2025 14:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977171#M378438</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-10-16T14:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977177#M378441</link>
      <description>&lt;P&gt;You already have the answer but note that I find that if you structure your program in this way the matching of the macro variable name with the value it will receive is more obvious.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select min(age)
     , max(age)
  into :min_age trimmed
     , :max_age trimmed
  from sashelp.class
;
quit;
%put MAX Age = "&amp;amp;max_age";
%put MIN Age = "&amp;amp;min_age";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Oct 2025 15:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977177#M378441</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-10-16T15:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977186#M378443</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442038"&gt;@PamG&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is a sample data. What I am trying to get at is that the order in which the variables are entered in PROC SQL when one of them is entered as INTO matters. Is there a way to get COUNT before SUM and assign COUNT to a macro variable in the same PROC SQL code?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First, as stated by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;we don't know your final goal here. That would be very helpful information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are only very rare cases where you need to put statistics like count and sum into a macro variable, and in fact there are better ways to determine these values than SQL. So I think the efficiency of what you are doing could improve, if only we knew what the final goal is.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Oct 2025 16:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977186#M378443</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-10-16T16:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977205#M378448</link>
      <description>&lt;P&gt;If you want to put two values from the same observation into a single macro variable then use SAS code to concatenate the values first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select catx(' -&amp;gt; ',count(x),sum(x)) into :a trimmed from one; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It you want to select values from multiple observations into a single macro variable then use the SEPARATED BY clause.&amp;nbsp; If you want to control the order then include an ORDER BY clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  select value 
    into :b separated by ' -&amp;gt; '
    from (
     select 2 as order,sum(x) format=best32. as value from one
      union 
     select 1 as order,count(x) format=best32. as value from one 
      ) 
    order by order
  ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2025 00:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977205#M378448</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-10-17T00:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977220#M378452</link>
      <description>&lt;P&gt;Is there a way to output these results to output window on SAS EG?&amp;nbsp; the %put statment&amp;nbsp; goes to log and using the following code, you cannot format the text.&amp;nbsp; I wonder if I should start another thread.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
	FILE PRINT;
	line1="MAX Age = &amp;amp;max_age, Min Age=&amp;amp;min_age";
	PUT #1 line1 10-25 ;
	FILE LOG;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Oct 2025 02:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977220#M378452</guid>
      <dc:creator>PamG</dc:creator>
      <dc:date>2025-10-17T02:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977221#M378453</link>
      <description>&lt;P&gt;If you just want to produce a report then I wouldn't bother to use macro variables.&lt;/P&gt;
&lt;P&gt;PROC SQL will print to the output window (if you don't include the NOPRINT option that I used to suppress it when creating macro variables).&amp;nbsp; Or use PROC SUMMARY or some other tool to make a dataset with the values you want and then use PROC PRINT or PROC REPORT to write your report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be good to start a new thread and include more details about the overall goal you are trying to achieve if you need more help.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2025 02:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977221#M378453</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-10-17T02:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL does not work with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977269#M378458</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;.  I started a new thread.</description>
      <pubDate>Fri, 17 Oct 2025 15:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-does-not-work-with-multiple-variables/m-p/977269#M378458</guid>
      <dc:creator>PamG</dc:creator>
      <dc:date>2025-10-17T15:27:32Z</dc:date>
    </item>
  </channel>
</rss>

