<?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: Help getting the Max Value from a table. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-getting-the-Max-Value-from-a-table/m-p/421278#M103642</link>
    <description>&lt;P&gt;That use is just a subquery&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table example as
   select name, sex, age
   from sashelp.class
   where age= (select max(age) from sashelp.class)
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;as long as that select returns a single value no problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Dec 2017 18:03:33 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-12-14T18:03:33Z</dc:date>
    <item>
      <title>Help getting the Max Value from a table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-getting-the-Max-Value-from-a-table/m-p/421253#M103634</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need some help getting the max value from a column in a table. I initially tried writing a function as such:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC FCMP OUTLIB=work.func.test;
	FUNCTION get_max(table $, column $);
		PROC SQL;
			SELECT MAX(column) INTO :ret FROM table;
		QUIT;
		RETURN ret;
	ENDSUB;
RUN;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it doesn't work. Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 17:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-getting-the-Max-Value-from-a-table/m-p/421253#M103634</guid>
      <dc:creator>dscamelo</dc:creator>
      <dc:date>2017-12-14T17:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help getting the Max Value from a table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-getting-the-Max-Value-from-a-table/m-p/421259#M103636</link>
      <description>&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you demonstrate exactly how you wanted to use that result? I am very sure you can't call proc sql in the middle of a data step or other Sql call. From the documentation: PROC &lt;FONT style="background-color: rgb(252, 222, 192);"&gt;FCMP&lt;/FONT&gt; enables you to write functions and CALL routines using DATA step syntax. You aren't using data set syntax so the creation probably fails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can place a value into a global macro variable with something like this:&lt;/P&gt;
&lt;PRE&gt;%macro max(table, column, target);
%global &amp;amp;target;
PROC SQL;
   SELECT MAX(&amp;amp;column) INTO : &amp;amp;target FROM &amp;amp;table;
QUIT;

%mend;

%max(sashelp.class,age,val);
%put &amp;amp;val;&lt;/PRE&gt;
&lt;P&gt;but that type of macro "function" can't be called in many places because of the Proc SQL portion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 17:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-getting-the-Max-Value-from-a-table/m-p/421259#M103636</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-14T17:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: Help getting the Max Value from a table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-getting-the-Max-Value-from-a-table/m-p/421265#M103637</link>
      <description>&lt;P&gt;Hi ballardw, thanks for&amp;nbsp;your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Being more specific, it doesn't work because, as you pointed out, PROC FCMP can't deal with PROC SQL commands inside it. The snippet I offered was meant to convey the idea of what I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need a simple function that can return the max value from a column in a table. I meant to use it as something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;
	CREATE TABLE work.op1 AS
	SELECT
		*
	FROM
		work.input1
	WHERE
		date_updated = &lt;U&gt;&lt;STRONG&gt;get_max&lt;/STRONG&gt;&lt;/U&gt;(other_table, date_updated);&lt;BR /&gt;
QUIT;&lt;/PRE&gt;&lt;P&gt;assuming the get_max from&amp;nbsp;original post had&amp;nbsp;worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your macro suggestion is something that had occured to me, but I mean to write a function and store it so everyone in my work group could use, rather than everyone having to include and run macros that use global variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I was clear with what I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 17:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-getting-the-Max-Value-from-a-table/m-p/421265#M103637</guid>
      <dc:creator>dscamelo</dc:creator>
      <dc:date>2017-12-14T17:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Help getting the Max Value from a table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-getting-the-Max-Value-from-a-table/m-p/421278#M103642</link>
      <description>&lt;P&gt;That use is just a subquery&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table example as
   select name, sex, age
   from sashelp.class
   where age= (select max(age) from sashelp.class)
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;as long as that select returns a single value no problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 18:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-getting-the-Max-Value-from-a-table/m-p/421278#M103642</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-14T18:03:33Z</dc:date>
    </item>
  </channel>
</rss>

