<?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: RESOLVE macro function to sum variables in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422507#M103897</link>
    <description>&lt;P&gt;You could follow Tom's example and create a loop to go over all your X values and then substitute the sum with any generic fucntion you are using.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**create array with distinct values of X;
proc sql noprint;
	select distinct(x) into :ValuesOfX separated by ' '
	from in;
%let NumValuesOfX = &amp;amp;SqlObs.;
	
**Generate test_data;
%macro test;

data test_data;
	set in;
	select(x);
		%do i=1 %to &amp;amp;NumValuesOfX.;
			%let XVal=%scan(&amp;amp;ValuesOfX., &amp;amp;i.);
			when ("&amp;amp;XVal.") rc= sum(of &amp;amp;XVal._:);	
		%end;
	end;
run;

proc print data= test_data noobs;
run;

%mend;	
%test;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 19 Dec 2017 21:36:19 GMT</pubDate>
    <dc:creator>lopezr</dc:creator>
    <dc:date>2017-12-19T21:36:19Z</dc:date>
    <item>
      <title>RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422472#M103881</link>
      <description>&lt;P&gt;Greetings!&lt;/P&gt;&lt;P&gt;I'd like to sum a set of variables, the set of which are identified by a variable in the dataset. I realize there are many ways to do this, but ultimately I'll be processing large output from PROC MCMC where array statements are unwieldy.&lt;/P&gt;&lt;P&gt;In the data set 'test' I identify the variable list to be summed by the first column labeled 'x', so that I will compute a_1+a_2+a_3 in the first row, then b_1+b_2+b_3 in the second row, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data in;
	input x $ a_1 a_2 a_3 b_1 b_2 b_3 c_1 c_2 c_3;
datalines;
a	1	1	1	2	2	2	3	3	3
b	1	1	1	2	2	2	3	3	3
c	1	1	1	2	2	2	3	3	3
;
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;The macro %vTest writes out the summation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro vtest(xVal);
0 %do i = 1 %to 3; +&amp;amp;xVal._&amp;amp;i. %end;
%mend vtest;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data set 'test_data' reads dataset 'in' and processes using the RESOLVE function and %vtest. Results are then printed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_data;
	set in;
   		rc = resolve(cats('%vtest(',x,')')); 
run;

options nocenter;
proc print data= test_data noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you can see, the column rc shows 0+a_1+a_2+a_3. I'd like rc to show the actual sum, i.e. 3, 6, and 9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;Garnett&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422472#M103881</guid>
      <dc:creator>gnet</dc:creator>
      <dc:date>2017-12-19T20:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422483#M103883</link>
      <description>&lt;P&gt;Well this certainly gets complicated, and I hope you are right that you can't use ARRAYS in your real-world situation, but I am skeptical.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you seem to have over-complicated things even in the macro case. I believe this is what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test_data;
	set in;
   		rc = %vtest(a); 
run;&lt;/PRE&gt;
&lt;P&gt;,&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422483#M103883</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-12-19T20:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422485#M103884</link>
      <description>&lt;P&gt;Wouldn't IML maybe be a better approach in this case?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422485#M103884</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-19T20:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422486#M103885</link>
      <description>&lt;P&gt;Thanks very much for looking at this! Your solution just resolves to a_1+a_2+a_3 for each row of the dataset. I'd like the summation over variables that can be defined by column x of the input dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422486#M103885</guid>
      <dc:creator>gnet</dc:creator>
      <dc:date>2017-12-19T20:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422488#M103886</link>
      <description>&lt;P&gt;Thanks for looking at this, Reeza.&lt;/P&gt;&lt;P&gt;IML might be the approach I take. I'd like to find a datastep + macro solution if possible.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422488#M103886</guid>
      <dc:creator>gnet</dc:creator>
      <dc:date>2017-12-19T20:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422489#M103887</link>
      <description>&lt;P&gt;If you want macro code to add numbers you need to pass the numbers to the macro environment.&amp;nbsp; It will know nothing of the data step variable A_1, let alone what value it has for this iteration of the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How many possible values of X are there?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set in ;
  select (x);
    when ('a') result = sum(of a_:);
    when ('b') result = sum(of b_:);
    when ('c') result = sum(of c_:);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422489#M103887</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-19T20:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422494#M103889</link>
      <description>&lt;P&gt;Thanks Tom!&lt;/P&gt;&lt;P&gt;There may be thousands of values of 'x', but more importantly the macro %vtest may be an arbitrary function and not just a sum. I used the sum in the example to make it easier to present.&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;Garnett&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422494#M103889</guid>
      <dc:creator>gnet</dc:creator>
      <dc:date>2017-12-19T20:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422497#M103890</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183320"&gt;@gnet&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for looking at this, Reeza.&lt;/P&gt;
&lt;P&gt;IML might be the approach I take. I'd like to find a datastep + macro solution if possible.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It might help to describe exactly what you are attempting. Summing within "columns", variables in SAS terminology, is usually done in either a summary procedure such as Proc Means or Summary. Summing multiple variables often done in data step or Proc SQL. Depending on needs Proc Report maybe able to do both.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will say that your example data is poor as you could sums of 3,&amp;nbsp; either within observation ("row") by adding a_1+a_2+a_3 OR adding the three rows for any of a_1, a_2 or a_3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;proc means data=in;
   var _numeric_;
   output out=summary (drop=_:) sum=;
run;&lt;/PRE&gt;
&lt;P&gt;Will sum each variable in the example data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If then need to sum the variables of a, b and c groups:&lt;/P&gt;
&lt;PRE&gt;data want;
   set summary;
   suma= sum(of a:);
   sumb= sum(of b:);
   sumc= sum(of c:);
   keep sum: ;
run;&lt;/PRE&gt;
&lt;P&gt;That proc means and data step could be turned into a macro if needed but seeing an actual use case with data that lets us know which way and specific sum should go might help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 21:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422497#M103890</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-19T21:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422498#M103891</link>
      <description>&lt;P&gt;It's not clear how you plan to define the rules and function - that's important.If you can provide some more details we can provide better options.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 21:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422498#M103891</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-19T21:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422501#M103892</link>
      <description>&lt;P&gt;You could;&lt;/P&gt;&lt;P&gt;1. Transpose&lt;/P&gt;&lt;P&gt;2. extract letter prefix from _name_ variable, this forms a group&lt;/P&gt;&lt;P&gt;3. look up with hash or any look up that you are comfortable with and execute sum&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183320"&gt;@gnet&lt;/a&gt;&amp;nbsp;Try this, if you still can't find it, I can show a demo using your sample piece shortly after my class&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 21:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422501#M103892</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-19T21:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422505#M103895</link>
      <description>&lt;P&gt;You could follow Tom's example but create a loop to go through all your values of x then write whichever generic function you use instead of sum.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**create array with distinct values of X;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;select distinct(x) into :ValuesOfX separated by ' '&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;from in;&lt;BR /&gt;%let NumValuesOfX = &amp;amp;SqlObs.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;**Generate test_data;&lt;BR /&gt;%macro test;&lt;BR /&gt;&lt;BR /&gt;data test_data;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set in;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;select(x);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;%do i=1 %to &amp;amp;NumValuesOfX.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;%let XVal=%scan(&amp;amp;ValuesOfX., &amp;amp;i.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;when ("&amp;amp;XVal.") rc= sum(of &amp;amp;XVal._:);&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;%end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data= test_data noobs;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%mend;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;%test;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Dec 2017 21:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422505#M103895</guid>
      <dc:creator>lopezr</dc:creator>
      <dc:date>2017-12-19T21:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422506#M103896</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183320"&gt;@gnet&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Tom!&lt;/P&gt;
&lt;P&gt;There may be thousands of values of 'x', but more importantly the macro %vtest may be an arbitrary function and not just a sum. I used the sum in the example to make it easier to present.&lt;/P&gt;
&lt;P&gt;Thanks again,&lt;/P&gt;
&lt;P&gt;Garnett&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"Thousands of values of 'X' " has the potential to have issues related to "thousands of macro variables" and having to adjust macro memory settings and other issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually "sum" using &amp;nbsp;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;xVal&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;_&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;I construct is a very poor approach because if any single variable is missing then the result is missing, unless that is your desired behavior.&lt;/P&gt;
&lt;P&gt;Perhaps you really want to use Proc FCMP to make your function which does allow passing an array of values and returning a single value&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 21:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422506#M103896</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-19T21:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422507#M103897</link>
      <description>&lt;P&gt;You could follow Tom's example and create a loop to go over all your X values and then substitute the sum with any generic fucntion you are using.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**create array with distinct values of X;
proc sql noprint;
	select distinct(x) into :ValuesOfX separated by ' '
	from in;
%let NumValuesOfX = &amp;amp;SqlObs.;
	
**Generate test_data;
%macro test;

data test_data;
	set in;
	select(x);
		%do i=1 %to &amp;amp;NumValuesOfX.;
			%let XVal=%scan(&amp;amp;ValuesOfX., &amp;amp;i.);
			when ("&amp;amp;XVal.") rc= sum(of &amp;amp;XVal._:);	
		%end;
	end;
run;

proc print data= test_data noobs;
run;

%mend;	
%test;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Dec 2017 21:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422507#M103897</guid>
      <dc:creator>lopezr</dc:creator>
      <dc:date>2017-12-19T21:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422516#M103903</link>
      <description>&lt;P&gt;Here is the demo, if you can play with this approach, you can bid good bye to the macro processor &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&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;&lt;STRONG&gt;data&lt;/STRONG&gt; in;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input x $ a_1 a_2 a_3 b_1 b_2 b_3 c_1 c_2 c_3;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;a&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;b&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;c&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;transpose&lt;/STRONG&gt; data=in out=w;&lt;/P&gt;&lt;P&gt;id x;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;&lt;P&gt;set w;&lt;/P&gt;&lt;P&gt;k=char(_name_,&lt;STRONG&gt;1&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; final_want;&lt;/P&gt;&lt;P&gt;if _n_=&lt;STRONG&gt;1&lt;/STRONG&gt; then do;&lt;/P&gt;&lt;P&gt;if &lt;STRONG&gt;0&lt;/STRONG&gt; then set want(keep=a k);&lt;/P&gt;&lt;P&gt;dcl hash h(dataset:'want(keep=a k)', multidata: 'y', ordered: 'y');&lt;/P&gt;&lt;P&gt;&amp;nbsp;h.definekey('k');&lt;/P&gt;&lt;P&gt;&amp;nbsp;h.definedata(all:'yes');&lt;/P&gt;&lt;P&gt;&amp;nbsp;h.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;set in(keep=x);&lt;/P&gt;&lt;P&gt;&amp;nbsp;sum=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;do while(h.do_over(key:x) eq &lt;STRONG&gt;0&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum+a;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 22:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422516#M103903</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-19T22:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422518#M103904</link>
      <description>&lt;P&gt;Not sure what the macro has to do with the problem. But if you want to generate code then first generate the code to a file and then use %INCLUDE to make it part of your data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=in(keep=x) out=xlist nodupkey;
  by x ;
run;

filename code temp;
data _null_;
  set xlist end=eof;
  file code ;
  if _n_=1 then put 'select (x);' ;
  put 'when (' x :$quote. ') rc=%vtest(' x ');' ;
  if eof then put 'end;' ;
run;

options mprint;
data want ;
  set in ;
%include code / source2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1271  options mprint;
1272  data want ;
1273    set in ;
1274  %include code / source2 ;
NOTE: %INCLUDE (level 1) file CODE is file C:\Users\...\#LN00069.
1275 +select (x);
1276 +when ("a" ) rc=%vtest(a );
MPRINT(VTEST):  0 +a_1 +a_2 +a_3
1277 +when ("b" ) rc=%vtest(b );
MPRINT(VTEST):  0 +b_1 +b_2 +b_3
1278 +when ("c" ) rc=%vtest(c );
MPRINT(VTEST):  0 +c_1 +c_2 +c_3
1279 +end;
NOTE: %INCLUDE (level 1) ending.
1280  run;

NOTE: There were 3 observations read from the data set WORK.IN.
NOTE: The data set WORK.WANT has 3 observations and 11 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 22:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422518#M103904</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-19T22:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422530#M103908</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;This is the idea that I was going for. I hadn't considered this approach to writing the code into a file and then running with %include inside the datastep.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 23:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422530#M103908</guid>
      <dc:creator>gnet</dc:creator>
      <dc:date>2017-12-19T23:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422531#M103909</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;This is a fascinating bit of code, and involves hash programming that I've never used. Looks like I have work to do!&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 23:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422531#M103909</guid>
      <dc:creator>gnet</dc:creator>
      <dc:date>2017-12-19T23:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: RESOLVE macro function to sum variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422563#M103922</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;gnet wrote&lt;EM&gt;:&lt;/EM&gt;&lt;BR /&gt;&lt;P&gt;&lt;EM&gt;Hi there,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;This is a fascinating bit of code, and involves hash programming that I've never used. &lt;STRONG&gt;Looks like I have work to do!&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Thanks again!&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Looks like I have work to do!" hmmm me too. That makes two of us. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Trick to be successful&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;1. Stay updated with posts from Tom, Art T, Xia Keshan, Mkeintz, Astounding, Reeza, Steve denham, Kurt, PG, Haikuo, Friedegg et al. They make our lives a whole lot easier. That's how I learn.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 01:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RESOLVE-macro-function-to-sum-variables-in-a-dataset/m-p/422563#M103922</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-20T01:15:57Z</dc:date>
    </item>
  </channel>
</rss>

