<?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 avoid warning message when creating macro variables in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-avoid-warning-message-when-creating-macro-variables-in/m-p/621298#M182642</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*This is all you need*/
proc sql ;
select count(distinct a) into: cntt trimmed from one;
select   a into :param1 -:param&amp;amp;cntt. 
from (select distinct b,a from one);
quit;

%put &amp;amp;param1;
%put &amp;amp;param2;
/*Or just even terse*/
proc sql ;
select   a into :param1 - 
from (select distinct b,a from one);
quit;

%put &amp;amp;param1;
%put &amp;amp;param2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 30 Jan 2020 19:52:19 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-01-30T19:52:19Z</dc:date>
    <item>
      <title>how to avoid warning message when creating macro variables in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-avoid-warning-message-when-creating-macro-variables-in/m-p/621286#M182635</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am getting a warning message when the the code. I am getting the output&amp;nbsp; i need .&amp;nbsp; I need to have param1 =&lt;CODE class=" language-sas"&gt;SS-S1 SSS &amp;gt;= 1 1&amp;nbsp; &amp;nbsp;and param2=SS-S1 SSS &amp;lt; 1.&amp;nbsp;&lt;/CODE&gt;&amp;nbsp;Please suggest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WARNING: The query as specified involves ordering by an item that doesn't appear in its SELECT clause. Since you are ordering&lt;BR /&gt;the output of a SELECT DISTINCT it may appear that some duplicates have not been eliminated.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input a $1-14 b 16;
datalines;
SS-S1 SSS &amp;gt;= 1 1
SS-S1 SSS &amp;lt; 1  2
;

proc sql;
select strip(put(count (distinct a), best.)) into: cntt from one;
select  distinct a into :param1 -:param&amp;amp;cntt. from one
order by b ;
quit;
	%put &amp;amp;param1;
%put &amp;amp;param2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 19:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-avoid-warning-message-when-creating-macro-variables-in/m-p/621286#M182635</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-01-30T19:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to avoid warning message when creating macro variables in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-avoid-warning-message-when-creating-macro-variables-in/m-p/621298#M182642</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*This is all you need*/
proc sql ;
select count(distinct a) into: cntt trimmed from one;
select   a into :param1 -:param&amp;amp;cntt. 
from (select distinct b,a from one);
quit;

%put &amp;amp;param1;
%put &amp;amp;param2;
/*Or just even terse*/
proc sql ;
select   a into :param1 - 
from (select distinct b,a from one);
quit;

%put &amp;amp;param1;
%put &amp;amp;param2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 19:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-avoid-warning-message-when-creating-macro-variables-in/m-p/621298#M182642</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-30T19:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to avoid warning message when creating macro variables in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-avoid-warning-message-when-creating-macro-variables-in/m-p/621315#M182649</link>
      <description>&lt;P&gt;You have two issues here.&amp;nbsp; The one the message is about is that you are trying to select distinct values of A but order the result be a different column.&amp;nbsp; If the same value of A has multiple values of B then your query will return multiple values of A.&lt;/P&gt;
&lt;P&gt;So if the same value of A has many values of B which of those values do you want to use for ordering? Perhaps the minimum value?&lt;/P&gt;
&lt;P&gt;So instead of using DISTINCT do a subquery using GROUP BY to get to one observation per value of A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select  a into :param1- 
from (select a,min(b) as b from one group by a)
order by b
;
%let cntt = &amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you will see a different message:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECT clause.
&lt;/PRE&gt;
&lt;P&gt;You could add the B variable to the select list.&amp;nbsp; But then you get a WARNING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WARNING: INTO clause specifies fewer host variables than columns listed in the SELECT clause.&lt;/PRE&gt;
&lt;P&gt;So you need to stuff B into something.&amp;nbsp; For example you could just have it create a macro variable named DUMMY and then ignore that macro variable.&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;proc sql noprint;
select a,b into :param1- ,:dummy
from (select min(b) as b,a from one group by a)
order by b
;
%let cntt = &amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course it looks like you can skip all of this nonsense and just generate the macro variables use a data step instead of PROC SQL.&amp;nbsp; Do your values of B really count sequentially like in your example?&amp;nbsp; Why not use the value of B to generate the macro variable name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set one end=eof;
  call symputx(cats('param',b),a);
  if eof then call symputx('cntt',b);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If not then use the automatic loop counter variable, _N_, instead of B .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 21:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-avoid-warning-message-when-creating-macro-variables-in/m-p/621315#M182649</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-30T21:51:47Z</dc:date>
    </item>
  </channel>
</rss>

