<?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 proc sql select variable name and value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867401#M342581</link>
    <description>&lt;P&gt;I'm running this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc means noprint data=have n; output out=want(drop=_type_ _freq_) n=;

proc sql;
  select name
  into :max_var separated by ' '
  from dictionary.columns
  where libname='WORK' and memname='want'
  and name ne 'n' group by 1 having n=max(n);
  quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My goal with the proc sql is to select the variable with highest 'n', store its name and value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is the error I'm getting:&lt;/P&gt;&lt;P&gt;ERROR: The following columns were not found in the contributing tables: n.&lt;/P&gt;</description>
    <pubDate>Fri, 31 Mar 2023 09:40:38 GMT</pubDate>
    <dc:creator>Satori</dc:creator>
    <dc:date>2023-03-31T09:40:38Z</dc:date>
    <item>
      <title>proc sql select variable name and value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867401#M342581</link>
      <description>&lt;P&gt;I'm running this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc means noprint data=have n; output out=want(drop=_type_ _freq_) n=;

proc sql;
  select name
  into :max_var separated by ' '
  from dictionary.columns
  where libname='WORK' and memname='want'
  and name ne 'n' group by 1 having n=max(n);
  quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My goal with the proc sql is to select the variable with highest 'n', store its name and value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is the error I'm getting:&lt;/P&gt;&lt;P&gt;ERROR: The following columns were not found in the contributing tables: n.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 09:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867401#M342581</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-03-31T09:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql select variable name and value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867407#M342585</link>
      <description>&lt;P&gt;If you look at DICTIONARY.COLUMNS (which is also SASHELP.VCOLUMN) you will see there is no variable N in this data set. But its really unclear why you want to use DICTIONARY.COLUMNS in the first place, there is no such thing as N and there is also no such thing as MAX(N) here. Please explain what you are trying to do.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 09:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867407#M342585</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-31T09:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql select variable name and value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867408#M342586</link>
      <description>I'm trying to get the name and count for the variable with highest number of non-missing, and storing it.</description>
      <pubDate>Fri, 31 Mar 2023 09:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867408#M342586</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-03-31T09:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql select variable name and value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867411#M342587</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173636"&gt;@Satori&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the ODS output dataset from PROC MEANS is more suitable for your purpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
set sashelp.heart;
run;

ods select none;
ods output summary=want;
proc means data=have n stackods;
run;
ods select all;

proc sql noprint;
select nliteral(variable), n into :max_var separated by ' ', :max_n
from want
having n=max(n);
quit;

%put &amp;amp;=max_var;
%put &amp;amp;=max_n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result in the log:&lt;/P&gt;
&lt;PRE&gt;MAX_VAR=AgeAtStart Diastolic Systolic
MAX_N=5209&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Mar 2023 10:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867411#M342587</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-03-31T10:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql select variable name and value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867412#M342588</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173636"&gt;@Satori&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I'm trying to get the name and count for the variable with highest number of non-missing, and storing it.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That information is not in DICTIONARY.COLUMNS. Not sure why you thought it was. It should be in data set WANT, as pointed out by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;. Isn't that why you created data set WANT, to know how many non-missing observations there are in HAVE?&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 10:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-variable-name-and-value/m-p/867412#M342588</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-31T10:22:53Z</dc:date>
    </item>
  </channel>
</rss>

