<?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: SAS Macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349249#M80984</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Normalizing a fat variable into key/value pairs

see
https://communities.sas.com/t5/Base-SAS-Programming/SAS-Macros/m-p/349115

HAVE
====

Up to 40 obs WORK.HAVE total obs=2

 FIRM     AFRICA_WIDE

 Firm1    Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3).Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)
 Firm2    Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3)

WANT (if you move the output statement inside the loop you will get the form you wanted or transpose want)


Up to 40 obs WORK.WANT total obs=7

Obs    FIRM      NAME      PROJECTS                                         BAND

 1     Firm1    AFRICA1    Corporate/M&amp;amp;A (Band 3)                            3
 2     Firm1    AFRICA2    Dispute Resolution (Band 2)                       2
 3     Firm1    AFRICA3    Projects &amp;amp; Energy (Band 3)                        3
 4     Firm1    AFRICA4    Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)     3

 5     Firm2    AFRICA1    Corporate/M&amp;amp;A (Band 3)                            3
 6     Firm2    AFRICA2    Dispute Resolution (Band 2)                       2
 7     Firm2    AFRICA3    Projects &amp;amp; Energy (Band 3)                        3

proc transpose data=want out=wantxpo;
by firm;
var band;
id projects;
run;quit;

                          CORPORATE_      DISPUTE_      PROJECTS___     ENERGY__
                          M_A__BAND_    RESOLUTION__     ENERGY__       MINING___
Obs    FIRM     _NAME_        3_          BAND_2_         BAND_3_         MINE

 1     Firm1     BAND         3              2               3              3
 2     Firm2     BAND         3              2               3


WORKING CODE

     * dimension (permax) are the max number of projects acroos all firs;

      array africas[&amp;amp;permax] $64 africa1-africa&amp;amp;permax;
      array africasvals[&amp;amp;permax] $5 africasvals1-africasvals&amp;amp;permax;

FULL SOLUTION

*                _              _       _
 _ __ ___   __ _| | _____    __| | __ _| |_ __ _
| '_ ` _ \ / _` | |/ / _ \  / _` |/ _` | __/ _` |
| | | | | | (_| |   &amp;lt;  __/ | (_| | (_| | || (_| |
|_| |_| |_|\__,_|_|\_\___|  \__,_|\__,_|\__\__,_|

;

data have;
 firm             ='Firm1';
 africa_wide      ='Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3).Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)';
 africa1          ='Corporate/M&amp;amp;A (Band 3)';
 africa2          ='Dispute Resolution (Band 2)';
 africa3          ='Projects &amp;amp; Energy (Band 3)';
 africa4          ='Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)';
 africa_corp      =3;
 africa_resolut   =2;
 africa_nrgy_mine =3;
 africa_nrgy_mine =3;
run;quit;


data have;
 firm             ='Firm1';
 africa_wide      ='Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3).Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)';
 output;
 firm             ='Firm2';
 africa_wide      ='Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3)';
 output;
run;quit;

*          _       _   _
 ___  ___ | |_   _| |_(_) ___  _ __
/ __|/ _ \| | | | | __| |/ _ \| '_ \
\__ \ (_) | | |_| | |_| | (_) | | | |
|___/\___/|_|\__,_|\__|_|\___/|_| |_|

;

data want;
  * you need to know the maximum number of africas, ie africa1-africa9?;
  if _n_ = 0 then do;
    rc=%sysfunc(dosubl('
      proc sql;
         select max(percnt) into :permax separated by ""
         from (select countc(africa_wide,".") + 1 as percnt from have group by firm)
      ;quit;
    '));
  end;
  put "&amp;amp;&amp;amp;permax";
  length projects $64;
  set have;
  array africas[&amp;amp;permax] $64 africa1-africa&amp;amp;permax;
  array africasvals[&amp;amp;permax] $5 africasvals1-africasvals&amp;amp;permax;
  do i = 1 to  countc(africa_wide,'.') + 1;
    africas[i]=scan(africa_wide,i,'.');
    africasvals[i]=compress(africas[i],,'kd');
    name=vname(africas[i]);
    projects=africas[i];
    band=compress(africas[i],,'kd');
    output;
  end;
  keep firm name projects band;;
run;quit;


3686  data want;
3687    length project $64;
3688    * you need to know the maximum number of africas, ie africa1-africa9?;
3689    if _n_ = 0 then do;
3690      rc=%sysfunc(dosubl('
NOTE: A GROUP BY clause has been discarded because neither the SELECT clause nor the optional
      HAVING clause of the associated table-expression referenced a summary function.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              3727.00k
      OS Memory           20468.00k
      Timestamp           04/11/2017 04:01:10 PM
      Step Count                        338  Switch Count  0


3691        proc sql;
3692           select max(percnt) into :permax separated by ""
3693           from (select countc(africa_wide,".") + 1 as percnt from have group by firm)
3694        ;quit;
3695      '));
3696    end;
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable PERMAX resolves to 4
3697    put "&amp;amp;&amp;amp;permax";
3698    set have;
3699    array africas[&amp;amp;permax] $64 africa1-africa&amp;amp;permax;
SYMBOLGEN:  Macro variable PERMAX resolves to 4
SYMBOLGEN:  Macro variable PERMAX resolves to 4
3700    array africasvals[&amp;amp;permax] $5 africasvals1-africasvals&amp;amp;permax;
SYMBOLGEN:  Macro variable PERMAX resolves to 4
SYMBOLGEN:  Macro variable PERMAX resolves to 4
3701    do i = 1 to  countc(africa_wide,'.') + 1;
3702      africas[i]=scan(africa_wide,i,'.');
3703      africasvals[i]=compress(africas[i],,'kd');
3704      name=vname(africas[i]);
3705      projects=africas[i];
3706      band=compress(africas[i],,'kd');
3707      output;
3708    end;
3709    keep firm name projects band;;
3710  run;

4
NOTE: There were 2 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 7 observations and 4 variables.
NOTE: DATA statement used (Total process time):




&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 11 Apr 2017 20:05:30 GMT</pubDate>
    <dc:creator>rogerjdeangelis</dc:creator>
    <dc:date>2017-04-11T20:05:30Z</dc:date>
    <item>
      <title>SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349115#M80937</link>
      <description>&lt;P&gt;I have a data set and have created new columns from an&amp;nbsp;original column called&amp;nbsp;"Africa". This cell contained several variables together that I wanted to isolate and place the new variables into new columns e.g. Africa1, Africa2, etc.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;E.g Africa= "Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Africa1 = "Banking &amp;amp; Finance&amp;nbsp;&lt;SPAN style="box-sizing: inherit;"&gt;(Band 3)"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="box-sizing: inherit;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Africa2 = "Corporate/M&amp;amp;A&amp;nbsp;(Band 2)"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="box-sizing: inherit;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Once I have done this I want to create a unique column that merges together the region and sector: E,g Africa_BF (this searches for&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="box-sizing: inherit;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;Africa and Banking and Finance variable) that reads all the columns in Africa (1,2,3..) to put them into the new column. I populate the new column with the band numeric and hence the scan&amp;nbsp;function. When creating the new column my code looks like the below:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;if index(upcase(africa_wide1),'BANKING &amp;amp; FINANCE')&amp;gt;0 then Africa_BF=scan(africa_wide1,-1);&lt;BR /&gt;if index(upcase(africa_wide2),'BANKING &amp;amp; FINANCE')&amp;gt;0 then Africa_BF=scan(africa_wide2,-1);&lt;BR /&gt;if index(upcase(africa_wide3),'BANKING &amp;amp; FINANCE')&amp;gt;0 then Africa_BF=scan(africa_wide3,-1);&lt;BR /&gt;if index(upcase(africa_wide4),'BANKING &amp;amp; FINANCE')&amp;gt;0 then Africa_BF=scan(africa_wide4,-1);&lt;BR /&gt;if index(upcase(africa_wide5),'BANKING &amp;amp; FINANCE')&amp;gt;0 then Africa_BF=scan(africa_wide5,-1);&lt;BR /&gt;if index(upcase(africa_wide6),'BANKING &amp;amp; FINANCE')&amp;gt;0 then Africa_BF=scan(africa_wide6,-1);&lt;BR /&gt;if index(upcase(africa_wide7),'BANKING &amp;amp; FINANCE')&amp;gt;0 then Africa_BF=scan(africa_wide7,-1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;if index(upcase(africa_wide1),'CORPORATE/M&amp;amp;A')&amp;gt;0 then Africa_Corp_MA=scan(africa_wide1,-1);&lt;BR /&gt;if index(upcase(africa_wide2),'CORPORATE/M&amp;amp;A')&amp;gt;0 then Africa_Corp_MA=scan(africa_wide2,-1);&lt;BR /&gt;if index(upcase(africa_wide3),'CORPORATE/M&amp;amp;A')&amp;gt;0 then Africa_Corp_MA=scan(africa_wide3,-1);&lt;BR /&gt;if index(upcase(africa_wide4),'CORPORATE/M&amp;amp;A')&amp;gt;0 then Africa_Corp_MA=scan(africa_wide4,-1);&lt;BR /&gt;if index(upcase(africa_wide5),'CORPORATE/M&amp;amp;A')&amp;gt;0 then Africa_Corp_MA=scan(africa_wide5,-1);&lt;BR /&gt;if index(upcase(africa_wide6),'CORPORATE/M&amp;amp;A')&amp;gt;0 then Africa_Corp_MA=scan(africa_wide6,-1);&lt;BR /&gt;if index(upcase(africa_wide7),'CORPORATE/M&amp;amp;A')&amp;gt;0 then Africa_Corp_MA=scan(africa_wide7,-1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;There are roughly 80 regions&amp;nbsp;and 40 sector types that would mean I would have to write code for hundreds of columns. Is there a more efficient way to do this? For each region there would be 40 possible outcomes of Sector/Region.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Many Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 13:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349115#M80937</guid>
      <dc:creator>cmoore</dc:creator>
      <dc:date>2017-04-11T13:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349123#M80941</link>
      <description>&lt;P&gt;First SAS Macro is&amp;nbsp;&lt;STRONG&gt;not&amp;nbsp;&lt;/STRONG&gt;needed!&lt;/P&gt;
&lt;P&gt;Look up array processing, something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array vals{*} africa_wide:;
  do i=1 to dim(vals);
    if vals{i}...;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;If you post test data&amp;nbsp;&lt;STRONG&gt;in the form of a datastep&lt;/STRONG&gt; then more acurate code can be provided.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 14:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349123#M80941</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-11T14:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349132#M80944</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please find attached test data. This is the desired output. In essence, rather than write out all of the IF statements to populate the new columns I wondered if there was a more efficient alternative? By creating the new columns like Africa_BF it would allow me to eye-ball the data across all of the the different firms in column A and compare. The problem I have is that for each region there would be 80 columns for each one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 14:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349132#M80944</guid>
      <dc:creator>cmoore</dc:creator>
      <dc:date>2017-04-11T14:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349134#M80946</link>
      <description>&lt;P&gt;Post data as text not XL and not attachement.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 14:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349134#M80946</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-04-11T14:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349138#M80948</link>
      <description>&lt;P&gt;Please see the text below as one example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Firm Name&lt;/TD&gt;&lt;TD&gt;Africa-wide&lt;/TD&gt;&lt;TD&gt;Africa_wide1&lt;/TD&gt;&lt;TD&gt;Africa_wide2&lt;/TD&gt;&lt;TD&gt;Africa_wide3&lt;/TD&gt;&lt;TD&gt;Africa-Wide - Corporate/MA&lt;/TD&gt;&lt;TD&gt;Africa-Wide - Dispute Resolution&lt;/TD&gt;&lt;TD&gt;Africa-Wide - Projects &amp;amp; Energy&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Firm1&lt;/TD&gt;&lt;TD&gt;Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3).Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)&lt;/TD&gt;&lt;TD&gt;Corporate/M&amp;amp;A (Band 3)&lt;/TD&gt;&lt;TD&gt;Dispute Resolution (Band 2)&lt;/TD&gt;&lt;TD&gt;Projects &amp;amp; Energy (Band 3)&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 14:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349138#M80948</guid>
      <dc:creator>cmoore</dc:creator>
      <dc:date>2017-04-11T14:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349145#M80950</link>
      <description>&lt;P&gt;Here's a suggestion that I think will make life much easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change the structure of the data.&amp;nbsp; Instead of creating a variable named Africa_wide_1, create a variable named (something like) Africa_wide_Corporate_MA.&amp;nbsp; Put the data into the right variable to begin with.&amp;nbsp; Your subsequent processing will be (relatively) easy if there is only one variable that holds 'Corporate M&amp;amp;A/(Band #)'.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 14:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349145#M80950</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-11T14:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349249#M80984</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Normalizing a fat variable into key/value pairs

see
https://communities.sas.com/t5/Base-SAS-Programming/SAS-Macros/m-p/349115

HAVE
====

Up to 40 obs WORK.HAVE total obs=2

 FIRM     AFRICA_WIDE

 Firm1    Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3).Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)
 Firm2    Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3)

WANT (if you move the output statement inside the loop you will get the form you wanted or transpose want)


Up to 40 obs WORK.WANT total obs=7

Obs    FIRM      NAME      PROJECTS                                         BAND

 1     Firm1    AFRICA1    Corporate/M&amp;amp;A (Band 3)                            3
 2     Firm1    AFRICA2    Dispute Resolution (Band 2)                       2
 3     Firm1    AFRICA3    Projects &amp;amp; Energy (Band 3)                        3
 4     Firm1    AFRICA4    Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)     3

 5     Firm2    AFRICA1    Corporate/M&amp;amp;A (Band 3)                            3
 6     Firm2    AFRICA2    Dispute Resolution (Band 2)                       2
 7     Firm2    AFRICA3    Projects &amp;amp; Energy (Band 3)                        3

proc transpose data=want out=wantxpo;
by firm;
var band;
id projects;
run;quit;

                          CORPORATE_      DISPUTE_      PROJECTS___     ENERGY__
                          M_A__BAND_    RESOLUTION__     ENERGY__       MINING___
Obs    FIRM     _NAME_        3_          BAND_2_         BAND_3_         MINE

 1     Firm1     BAND         3              2               3              3
 2     Firm2     BAND         3              2               3


WORKING CODE

     * dimension (permax) are the max number of projects acroos all firs;

      array africas[&amp;amp;permax] $64 africa1-africa&amp;amp;permax;
      array africasvals[&amp;amp;permax] $5 africasvals1-africasvals&amp;amp;permax;

FULL SOLUTION

*                _              _       _
 _ __ ___   __ _| | _____    __| | __ _| |_ __ _
| '_ ` _ \ / _` | |/ / _ \  / _` |/ _` | __/ _` |
| | | | | | (_| |   &amp;lt;  __/ | (_| | (_| | || (_| |
|_| |_| |_|\__,_|_|\_\___|  \__,_|\__,_|\__\__,_|

;

data have;
 firm             ='Firm1';
 africa_wide      ='Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3).Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)';
 africa1          ='Corporate/M&amp;amp;A (Band 3)';
 africa2          ='Dispute Resolution (Band 2)';
 africa3          ='Projects &amp;amp; Energy (Band 3)';
 africa4          ='Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)';
 africa_corp      =3;
 africa_resolut   =2;
 africa_nrgy_mine =3;
 africa_nrgy_mine =3;
run;quit;


data have;
 firm             ='Firm1';
 africa_wide      ='Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3).Projects &amp;amp; Energy: Mining &amp;amp; Minerals (Band 3)';
 output;
 firm             ='Firm2';
 africa_wide      ='Corporate/M&amp;amp;A (Band 3).Dispute Resolution (Band 2).Projects &amp;amp; Energy (Band 3)';
 output;
run;quit;

*          _       _   _
 ___  ___ | |_   _| |_(_) ___  _ __
/ __|/ _ \| | | | | __| |/ _ \| '_ \
\__ \ (_) | | |_| | |_| | (_) | | | |
|___/\___/|_|\__,_|\__|_|\___/|_| |_|

;

data want;
  * you need to know the maximum number of africas, ie africa1-africa9?;
  if _n_ = 0 then do;
    rc=%sysfunc(dosubl('
      proc sql;
         select max(percnt) into :permax separated by ""
         from (select countc(africa_wide,".") + 1 as percnt from have group by firm)
      ;quit;
    '));
  end;
  put "&amp;amp;&amp;amp;permax";
  length projects $64;
  set have;
  array africas[&amp;amp;permax] $64 africa1-africa&amp;amp;permax;
  array africasvals[&amp;amp;permax] $5 africasvals1-africasvals&amp;amp;permax;
  do i = 1 to  countc(africa_wide,'.') + 1;
    africas[i]=scan(africa_wide,i,'.');
    africasvals[i]=compress(africas[i],,'kd');
    name=vname(africas[i]);
    projects=africas[i];
    band=compress(africas[i],,'kd');
    output;
  end;
  keep firm name projects band;;
run;quit;


3686  data want;
3687    length project $64;
3688    * you need to know the maximum number of africas, ie africa1-africa9?;
3689    if _n_ = 0 then do;
3690      rc=%sysfunc(dosubl('
NOTE: A GROUP BY clause has been discarded because neither the SELECT clause nor the optional
      HAVING clause of the associated table-expression referenced a summary function.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              3727.00k
      OS Memory           20468.00k
      Timestamp           04/11/2017 04:01:10 PM
      Step Count                        338  Switch Count  0


3691        proc sql;
3692           select max(percnt) into :permax separated by ""
3693           from (select countc(africa_wide,".") + 1 as percnt from have group by firm)
3694        ;quit;
3695      '));
3696    end;
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable PERMAX resolves to 4
3697    put "&amp;amp;&amp;amp;permax";
3698    set have;
3699    array africas[&amp;amp;permax] $64 africa1-africa&amp;amp;permax;
SYMBOLGEN:  Macro variable PERMAX resolves to 4
SYMBOLGEN:  Macro variable PERMAX resolves to 4
3700    array africasvals[&amp;amp;permax] $5 africasvals1-africasvals&amp;amp;permax;
SYMBOLGEN:  Macro variable PERMAX resolves to 4
SYMBOLGEN:  Macro variable PERMAX resolves to 4
3701    do i = 1 to  countc(africa_wide,'.') + 1;
3702      africas[i]=scan(africa_wide,i,'.');
3703      africasvals[i]=compress(africas[i],,'kd');
3704      name=vname(africas[i]);
3705      projects=africas[i];
3706      band=compress(africas[i],,'kd');
3707      output;
3708    end;
3709    keep firm name projects band;;
3710  run;

4
NOTE: There were 2 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 7 observations and 4 variables.
NOTE: DATA statement used (Total process time):




&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Apr 2017 20:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349249#M80984</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-04-11T20:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349339#M81009</link>
      <description>&lt;P&gt;Thanks very much for your help&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 07:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macros/m-p/349339#M81009</guid>
      <dc:creator>cmoore</dc:creator>
      <dc:date>2017-04-12T07:39:40Z</dc:date>
    </item>
  </channel>
</rss>

