<?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: macro array for summing the letter of codes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45457#M9398</link>
    <description>A less elegent solution but doable. Just very close with this. Thank you for the suggestion...</description>
    <pubDate>Thu, 11 Sep 2008 21:24:39 GMT</pubDate>
    <dc:creator>_LB</dc:creator>
    <dc:date>2008-09-11T21:24:39Z</dc:date>
    <item>
      <title>macro array for summing the letter of codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45453#M9394</link>
      <description>Hello all!&lt;BR /&gt;
&lt;BR /&gt;
Hopefully someone can help me debug this program.&lt;BR /&gt;
&lt;BR /&gt;
Right below is the starting mock table that outlines the problem... &lt;BR /&gt;
&lt;B&gt;(The tables don't render properly)&lt;/B&gt;&lt;BR /&gt;
Patient_Number    Day1  Day2  Day 3&lt;BR /&gt;
123                      A       B        A &lt;BR /&gt;
124                      A       B        C&lt;BR /&gt;
&lt;BR /&gt;
The letters represent codes that have to be converted into their own variables and then summed so that what you have is: &lt;BR /&gt;
&lt;BR /&gt;
Patient_Number    Day1  Day2  Day 3   A   B   C&lt;BR /&gt;
123                      A       B        A         2   1    0&lt;BR /&gt;
124                      A       B        C         1   1    1 &lt;BR /&gt;
&lt;BR /&gt;
The first part of the macro creates the list and then there is an indirect call to it.&lt;BR /&gt;
The second part attempts to create an array for every code to accomplish the above. The codes are part of a dataset...&lt;BR /&gt;
&lt;BR /&gt;
the macro almost works as it does pass each code through. Except I am running into a hitch at the last moment. The problem is coming down to an improper "when" and/or improper do blocks somewhere. &lt;BR /&gt;
&lt;BR /&gt;
 The code and then part of the log follows below. Any assistance would be greatly appreciated!&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;THIS PART WORKS!&lt;/B&gt;&lt;BR /&gt;
%macro split (data=, var=);&lt;BR /&gt;
   proc sort data=&amp;amp;data(keep=&amp;amp;var) out=values nodupkey;&lt;BR /&gt;
    by &amp;amp;var;&lt;BR /&gt;
   run;&lt;BR /&gt;
   data _null_;&lt;BR /&gt;
      set values end=last;&lt;BR /&gt;
      call symputx('site'||left(_n_),&amp;amp;var);&lt;BR /&gt;
      if last then call symputx('count',_n_);&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;B&gt;THIS PART DOES NOT!&lt;/B&gt;&lt;BR /&gt;
DATA ALLDATA;&lt;BR /&gt;
MERGE PTS INPUTDATA;&lt;BR /&gt;
BY MR_;	&lt;BR /&gt;
select(&amp;amp;var);&lt;BR /&gt;
%do i=1 %to &amp;amp;count;&lt;BR /&gt;
when("&amp;amp;&amp;amp;site&amp;amp;i")  %do;&lt;BR /&gt;
array Cod&amp;amp;&amp;amp;site&amp;amp;i [7] Day1-Day7;	&lt;BR /&gt;
Code&amp;amp;&amp;amp;site&amp;amp;i=0;&lt;BR /&gt;
DO I=1 to 7;&lt;BR /&gt;
	If Cod&amp;amp;&amp;amp;site&amp;amp;i&lt;I&gt;="&amp;amp;&amp;amp;site&amp;amp;i" then Code&amp;amp;&amp;amp;site&amp;amp;i=Code&amp;amp;&amp;amp;site&amp;amp;i+1;&lt;BR /&gt;
end;&lt;BR /&gt;
%END;&lt;BR /&gt;
&lt;BR /&gt;
  %END;&lt;BR /&gt;
drop I;&lt;BR /&gt;
  run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%mend split;&lt;BR /&gt;
%split(data=Codes, var=code)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
  Program Log:&lt;BR /&gt;
&lt;BR /&gt;
   DATA ALLDATA;&lt;BR /&gt;
MPRINT(SPLIT):   MERGE PTS INPUTDATA;&lt;BR /&gt;
MPRINT(SPLIT):   BY MR_;&lt;BR /&gt;
MPRINT(SPLIT):   select(code);&lt;BR /&gt;
NOTE: Line generated by the invoked macro "SPLIT".&lt;BR /&gt;
5     array Cod&amp;amp;&amp;amp;site&amp;amp;i [7] Day1-Day7; Code&amp;amp;&amp;amp;site&amp;amp;i=0; DO I=1 to 7;     If&lt;BR /&gt;
      -----&lt;BR /&gt;
      180&lt;BR /&gt;
5  ! Cod&amp;amp;&amp;amp;site&amp;amp;i&lt;I&gt;="&amp;amp;&amp;amp;site&amp;amp;i" then Code&amp;amp;&amp;amp;site&amp;amp;i=Code&amp;amp;&amp;amp;site&amp;amp;i+1; end;&lt;BR /&gt;
MPRINT(SPLIT):   when("A") array CodA [7] Day1-Day7;&lt;BR /&gt;
MPRINT(SPLIT):   CodeA=0;&lt;BR /&gt;
ERROR: Expecting "WHEN", "OTHERWISE", or "END".&lt;BR /&gt;
MPRINT(SPLIT):   DO I=1 to 7;&lt;BR /&gt;
MPRINT(SPLIT):   If CodA&lt;I&gt;="A" then CodeA=CodeA+1;&lt;BR /&gt;
MPRINT(SPLIT):   end;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;</description>
      <pubDate>Thu, 11 Sep 2008 18:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45453#M9394</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2008-09-11T18:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: macro array for summing the letter of codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45454#M9395</link>
      <description>Your %DO needs to be a DATA step DO statement -- to go with your SELECT/WHEN/END/OTHERWISE/END paragraph construct.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 11 Sep 2008 18:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45454#M9395</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-09-11T18:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: macro array for summing the letter of codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45455#M9396</link>
      <description>Scott;&lt;BR /&gt;
Thanks for the tip! Got me one inch closer. Now it seems to run through but I get the errors:&lt;BR /&gt;
NOTE: Character values have been converted to numeric values at the places given by:&lt;BR /&gt;
      (Line):(Column).&lt;BR /&gt;
      1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1&lt;BR /&gt;
      1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1&lt;BR /&gt;
      1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1   1:1&lt;BR /&gt;
NOTE: Variable code is uninitialized.&lt;BR /&gt;
NOTE: Invalid numeric data, 'A' , at line 1 column 1.&lt;BR /&gt;
&lt;BR /&gt;
So it works for the first code but then stops...still playing with it. &lt;BR /&gt;
&lt;BR /&gt;
Lawrence</description>
      <pubDate>Thu, 11 Sep 2008 20:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45455#M9396</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2008-09-11T20:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: macro array for summing the letter of codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45456#M9397</link>
      <description>Suggest you have a look at PROC TRANSPOSE, instead.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 11 Sep 2008 21:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45456#M9397</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-09-11T21:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: macro array for summing the letter of codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45457#M9398</link>
      <description>A less elegent solution but doable. Just very close with this. Thank you for the suggestion...</description>
      <pubDate>Thu, 11 Sep 2008 21:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45457#M9398</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2008-09-11T21:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: macro array for summing the letter of codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45458#M9399</link>
      <description>Hi: &lt;BR /&gt;
Regarding this: &lt;B&gt;&lt;BR /&gt;
(The tables don't render properly) &lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
when you want to show code or the SAS log or a mock table where it would be swell if everything lined up, like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Patient_Number Day1 Day2 Day3&lt;BR /&gt;
123              A    B    A &lt;BR /&gt;
124              A    B    C&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
All you need to do is surround your code and/or your table with the PRE tags. Only these are not HTML &amp;lt;PRE&amp;gt; tags, the tag is&lt;BR /&gt;
squarebracket-PRE-squarebracket_close&lt;BR /&gt;
squarebracket-/PRE-squarebracket_close or&lt;BR /&gt;
&lt;BR /&gt;
(PRE) and (/PRE) &lt;BR /&gt;
 &lt;BR /&gt;
except where I have the (, you would put [ and where I have the ), you would put ] -- that will tell the forum text editor and posting manager to NOT format anything within these special PRE tags.&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 11 Sep 2008 21:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45458#M9399</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-09-11T21:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: macro array for summing the letter of codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45459#M9400</link>
      <description>Thanks for how-to...I am brand spanking new  to the forum wiull abide by this in the future... &lt;BR /&gt;
~LB</description>
      <pubDate>Thu, 11 Sep 2008 21:52:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45459#M9400</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2008-09-11T21:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: macro array for summing the letter of codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45460#M9401</link>
      <description>I would like to thank Scott again for his help. Figured out the last part and now it works!</description>
      <pubDate>Thu, 11 Sep 2008 22:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-array-for-summing-the-letter-of-codes/m-p/45460#M9401</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2008-09-11T22:39:26Z</dc:date>
    </item>
  </channel>
</rss>

