<?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 build a set of macro variables to store the max value  for each group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945930#M370511</link>
    <description>I am learning how to set up macro. Just try to understand how to extract the needed info from a dataset  and put it into a macro variable.</description>
    <pubDate>Wed, 02 Oct 2024 12:19:01 GMT</pubDate>
    <dc:creator>stataq</dc:creator>
    <dc:date>2024-10-02T12:19:01Z</dc:date>
    <item>
      <title>how to build a set of macro variables to store the max value  for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945859#M370500</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to get max value by group and assign it to a set of macro variables. Can anyone please help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My codes were able to get the max value for each group.(might not be a smart way. If you know a better way, please share your thoughts. thanks.)&amp;nbsp; but how can create macro variables base on the groups we have?&lt;/P&gt;
&lt;PRE&gt;data have;
input group $  value;
datalines;
g1 30
g2 37
g2 76
g3 22
g3 84
g4 15
g4 21
g4 94
g4 73
;
run;

proc sort;
by group descending value  ;
run; 
data want (keep= group max_v);
   set have;
   by group;
   retain max_v;
   if first.group then max_v= value;
run;

proc sort nodupkey;
by _all_;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="stataq_0-1727829372964.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100799i729509F35BECA32D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="stataq_0-1727829372964.png" alt="stataq_0-1727829372964.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here we have 4 group, the ideal macro variables are&lt;/P&gt;
&lt;PRE&gt;%let grp1=30; %let grp2=76;&amp;nbsp; %let grp3=84; %let grp4=94;&lt;/PRE&gt;
&lt;P&gt;Is there a smart way to build those macro variables automatically?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 00:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945859#M370500</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-10-02T00:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to build a set of macro variables to store the max value  for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945861#M370501</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input group $  value;
datalines;
g1 30
g2 37
g2 76
g3 22
g3 84
g4 15
g4 21
g4 94
g4 73
;
run;

proc sql noprint;
	select max(value)
	into :grp1-
	from have
	group by group;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Oct 2024 01:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945861#M370501</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2024-10-02T01:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to build a set of macro variables to store the max value  for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945870#M370504</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13868"&gt;@AhmedAl_Attar&lt;/a&gt;&amp;nbsp;Thanks for the prompt answer. What if there is null value in group? How to assign macro variable only for non-null group?&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data have;
input group $  value;
datalines;
g1 30
g2 37
g2 76
g3 22
g3 84
g4 15
g4 21
   94
g4 73
;
run;&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 02 Oct 2024 02:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945870#M370504</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-10-02T02:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to build a set of macro variables to store the max value  for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945892#M370507</link>
      <description>Use a WHERE clause in the SQL.</description>
      <pubDate>Wed, 02 Oct 2024 07:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945892#M370507</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-10-02T07:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to build a set of macro variables to store the max value  for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945904#M370508</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=have;
class group;
var value;
output out=want max()=;
run;

data _null_;
set want;
call symputx(group,value);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I seriously question the need for macro variables; for all purposes I see, the want dataset is better suited.&lt;/P&gt;
&lt;P&gt;What are you intending to do with those macro variables?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 08:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945904#M370508</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-10-02T08:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to build a set of macro variables to store the max value  for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945917#M370509</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/448857"&gt;@stataq&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically, the missing value would be considered as a fifth grouping value, and the below SQL statement would generate 5 macros (grp1 -- grp5), where grp1 represents the null/missing value.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select max(value)
	into :grp1-
	from have
	/*Where group is not null*/ /* This would ignore null/missing values */
	group by group;
quit;
%put _user_;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;But if you want to exclude the null/missing group value, then use where clause as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has suggested already.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 09:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945917#M370509</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2024-10-02T09:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to build a set of macro variables to store the max value  for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945919#M370510</link>
      <description>&lt;P&gt;Hello, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/448857"&gt;@stataq&lt;/a&gt; , excellent advice from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; , please tell us (as he said) the big picture. Why you need these in macro variables? What are you going to do with the macro variables? (And in fact, knowing the big picture is something you should tell us every time you post a question here, we need explanation of the problem, explanation of the big picture, rather than a simple question about code). When we have that big picture explanation, we can often come up with a better solution than the one you are trying to program. For example, if you want to subtract the mean from the data in each group (that's the big picture description), no macro variables are needed, you can use PROC STDIZE and get it done with one PROC call.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 10:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945919#M370510</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-02T10:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to build a set of macro variables to store the max value  for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945930#M370511</link>
      <description>I am learning how to set up macro. Just try to understand how to extract the needed info from a dataset  and put it into a macro variable.</description>
      <pubDate>Wed, 02 Oct 2024 12:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945930#M370511</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-10-02T12:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to build a set of macro variables to store the max value  for each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945931#M370512</link>
      <description>&lt;P&gt;Part of learning macros is learning when NOT to use macros. As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;said: "&lt;SPAN&gt;But I seriously question the need for macro variables; for all purposes I see, the want dataset is better suited."&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 12:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-build-a-set-of-macro-variables-to-store-the-max-value-for/m-p/945931#M370512</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-02T12:25:10Z</dc:date>
    </item>
  </channel>
</rss>

