<?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 Macro - Automatic Combination in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652277#M195798</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a core dataset which I use to sum up the data for my assignments. The code I use currently is good for pulling out information on students who have the same first name, their age groups and the total number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Core dataset:&lt;/P&gt;&lt;P&gt;Forename&amp;nbsp; &amp;nbsp; Surname&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&lt;/P&gt;&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Mayo&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;32&lt;/P&gt;&lt;P&gt;Rupi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ketchup&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 39&lt;/P&gt;&lt;P&gt;Harry&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Mustard&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;etc etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How I currently use the data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Forename&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&amp;lt;21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&amp;gt;21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Total&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;18&lt;/P&gt;&lt;P&gt;Rupi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;Harry&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 14&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;P&gt;Forename&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&amp;lt;21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&amp;gt;21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Total&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;TomRupi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;38&lt;/P&gt;&lt;P&gt;etc etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I write piece of code (macro i think) which would automatically work out the Age groups and total combining two students together? e.g. Tom and Rupi, Tom and Harry, Harry and Rupi etc. The key thing I want to do here is automate the code so I would not have to type the combination myself in the code. SAS would ideally look at variable 1 and variable 2 then variable 1 and variable 3 etc. To keep it simple-ish the three Forenames in the core dataset are Tom, Rupi and Harry.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really sorry if this is too vague. I am happy to provide more information before any help is given.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Jacko&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jun 2020 15:08:13 GMT</pubDate>
    <dc:creator>JackoNewbie</dc:creator>
    <dc:date>2020-06-01T15:08:13Z</dc:date>
    <item>
      <title>Macro - Automatic Combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652277#M195798</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a core dataset which I use to sum up the data for my assignments. The code I use currently is good for pulling out information on students who have the same first name, their age groups and the total number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Core dataset:&lt;/P&gt;&lt;P&gt;Forename&amp;nbsp; &amp;nbsp; Surname&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&lt;/P&gt;&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Mayo&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;32&lt;/P&gt;&lt;P&gt;Rupi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ketchup&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 39&lt;/P&gt;&lt;P&gt;Harry&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Mustard&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;etc etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How I currently use the data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Forename&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&amp;lt;21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&amp;gt;21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Total&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;18&lt;/P&gt;&lt;P&gt;Rupi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;Harry&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 14&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;P&gt;Forename&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&amp;lt;21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&amp;gt;21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Total&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;TomRupi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;38&lt;/P&gt;&lt;P&gt;etc etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I write piece of code (macro i think) which would automatically work out the Age groups and total combining two students together? e.g. Tom and Rupi, Tom and Harry, Harry and Rupi etc. The key thing I want to do here is automate the code so I would not have to type the combination myself in the code. SAS would ideally look at variable 1 and variable 2 then variable 1 and variable 3 etc. To keep it simple-ish the three Forenames in the core dataset are Tom, Rupi and Harry.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really sorry if this is too vague. I am happy to provide more information before any help is given.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Jacko&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 15:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652277#M195798</guid>
      <dc:creator>JackoNewbie</dc:creator>
      <dc:date>2020-06-01T15:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro - Automatic Combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652279#M195799</link>
      <description>&lt;P&gt;You actually want to combine names??? Why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HOW are you currently creating that output? And are you looking for a data set for further processing or a report for people to read?&lt;/P&gt;
&lt;P&gt;How do you want to indicate which values to pull?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Variable1 and variable2, Variable1 and Variable3??? Please actually use variable names.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 15:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652279#M195799</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-01T15:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro - Automatic Combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652281#M195800</link>
      <description>&lt;P&gt;Can you please post a full example? Include your input data and EXACTLY what you expect as output from that input data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect generating a custom multilabel format is the quickest solution here. You can use PROC MEANS/TABULATE to get the output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Generate a format for age&lt;/P&gt;
&lt;P&gt;2. Generate a format for names, a multilabel format with each 2 way combination of names&lt;/P&gt;
&lt;P&gt;3. Use PROC TABULATE to apply the formats and calculate your summaries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need a macro for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, don't have time to fully work through this, but here's a start. Pretty sure the format part is right, but not the tabulate part.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value age_fmt
low - 14 = '&amp;lt;14'
14 - high = '14+';
run;

proc sql;
create table name_list_fmt as
select t1.name as start, catx(" - ", t1.name,  t2.name) as label, 'C' as type, 'M' as HLO, "name_fmt" as fmtname
from sashelp.class as t1, sashelp.class as t2
where t1.name&amp;gt;t2.name;
quit;

proc format cntlin=name_list_fmt;
run;

proc tabulate data=sashelp.class;
class age;
class name / mlf;
format age age_fmt. name $name_fmt.;
table name, age*N / printmiss;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 15:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652281#M195800</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-01T15:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro - Automatic Combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652284#M195801</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277136"&gt;@JackoNewbie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a core dataset which I use to sum up the data for my assignments. The code I use currently is good for pulling out information on students who have the same first name, their age groups and the total number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Core dataset:&lt;/P&gt;
&lt;P&gt;Forename&amp;nbsp; &amp;nbsp; Surname&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&lt;/P&gt;
&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Mayo&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;32&lt;/P&gt;
&lt;P&gt;Rupi&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ketchup&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 39&lt;/P&gt;
&lt;P&gt;Harry&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Mustard&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;
&lt;P&gt;etc etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The key thing I want to do here is automate the code so I would not have to type the combination myself in the code. SAS would ideally look at &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;variable 1 and variable 2 then variable 1 and variable 3 etc&lt;/STRONG&gt;&lt;/FONT&gt;. To keep it simple-ish the three Forenames in the core dataset are Tom, Rupi and Harry.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You've only shown name and age and how they're used. Where do these other variables come from? How are they related?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 15:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652284#M195801</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-01T15:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro - Automatic Combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652437#M195876</link>
      <description>&lt;P&gt;So sorry.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The surname doesn't come into this as it is just part of my core dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data person;
   infile datalines delimiter=','; 
   input Forename $ Surname $ Age;
   datalines;                      
Tom,Mayo,32
Rupi,Ketchup,39
Harry,Mustard,20
Tom,Blog,8
Rupi,Juniper,14
Harry,Potter,18
Tom,Peach,12
Rupi,Apple,49
Harry,Maguire,1

;

proc sql;
create table final_assignment as
select 
distinct forename,
sum(case when Age &amp;lt; 22 then 1 else 0 end) as AgeUnder21,
sum(case when Age &amp;gt; 21 then 1 else 0 end) as AgeOver21,
count (age) as total

from person
group by 1
;quit;

Want:

Forenames		AgeUnder21		AgeOver21		Total
Harry - Rupi			4				2			6
Harry - Tom			5				1			6
Rupi - Tom			3				3			6&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jun 2020 06:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652437#M195876</guid>
      <dc:creator>JackoNewbie</dc:creator>
      <dc:date>2020-06-02T06:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro - Automatic Combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652442#M195877</link>
      <description>&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
input FORENAME $ SURNAME $ AGE ;
cards;
Tom Mayo 32
Rupi Ketchup 39
Harry Mustard 20
run;

proc sql;
  create table WANT as
  select  
        catx('-',a.FORENAME, b.FORENAME)
      , sum((a.AGE&amp;lt;22)+(b.AGE&amp;lt;22)) as AGEUNDER21
      , sum((a.AGE&amp;gt;21)+(b.AGE&amp;gt;21)) as AGEOVER21
      , sum(calculated AGEUNDER21, calculated AGEOVER21) as TOTAL
  from HAVE a, HAVE b
  where a.FORENAME &amp;gt; b.FORENAME
  group by 1;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;&lt;A name="IDX" target="_blank"&gt;&lt;/A&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col"&gt;&amp;nbsp;&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;AGEUNDER21&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;AGEOVER21&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;TOTAL&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Rupi-Harry&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Tom-Harry&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Tom-Rupi&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 07:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652442#M195877</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-02T07:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro - Automatic Combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652604#M195946</link>
      <description>&lt;P&gt;And this bit shows exactly why I find the combined names to be a very questionable item for a report:&lt;/P&gt;
&lt;PRE&gt;Forenames		AgeUnder21		AgeOver21		Total
Harry - Rupi			4				2			6
Harry - Tom			5				1			6
Rupi - Tom			3				3			6&lt;/PRE&gt;
&lt;P&gt;Even occasional duplicates of the name appearing in a list makes it questionable on how to interpret the data.&lt;/P&gt;
&lt;P&gt;I &lt;STRONG&gt;might&lt;/STRONG&gt; make sense to use a unique personal identifier and combine those so it is somewhat more obvious that there data is not just plain inconsistent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, please describe &lt;STRONG&gt;exactly&lt;/STRONG&gt; what helpful information the combine forenames adds to that report. Or how the output data will actually be used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your particular example above would really make me believe that "Harry-Rupi" should be a combined version of "Harry-Tom" and "Rupi-Tom" in some form.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 16:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Automatic-Combination/m-p/652604#M195946</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-02T16:25:16Z</dc:date>
    </item>
  </channel>
</rss>

