<?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: Run macro (with a value from column as parameter) for every observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824291#M325521</link>
    <description>&lt;P&gt;&amp;nbsp;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The real example is that I have ca. 15 columns with numerical value. Then, I need to find the minimal one, I am doing it using arrays:&lt;/P&gt;&lt;PRE&gt; lowest_value = &lt;SPAN&gt;min&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;of columns&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;*]);&lt;/SPAN&gt;
 index_lowest_value = whichn&lt;SPAN&gt;(&lt;/SPAN&gt;lowest_value, of columns&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;*]);&lt;/SPAN&gt;
 column_lowest_value = &lt;SPAN&gt;vname&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;columns&lt;SPAN&gt;[&lt;/SPAN&gt;index_lowest_value&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I need to implement some logic for columns other that &lt;EM&gt;column_lowest_value &lt;/EM&gt;(using some loops and so on)&lt;EM&gt;,&lt;/EM&gt; so I try run the macro with &lt;EM&gt;column_lowest_value&lt;/EM&gt; as a parameter - something like that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;call symput('lowest', column_lowest_value, 'g');
%do_sth(&amp;amp;lowest.);

/* or: */
call execute('%do_sth('||lowest||');');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is that I need to do that dynamically, during processing. I am thinking about some workaround, but no idea so far &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jul 2022 07:10:40 GMT</pubDate>
    <dc:creator>filippo_kow</dc:creator>
    <dc:date>2022-07-20T07:10:40Z</dc:date>
    <item>
      <title>Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824168#M325448</link>
      <description>&lt;P&gt;&amp;nbsp;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my dataset I would like to run a macro for every observation, and pass to that macro a value from a particular column.&lt;/P&gt;&lt;P&gt;So I would like to do something like that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data test;
 set some_data_set;
 /* I have a column, let's say "VALUE", and for every observation I would like to call a macro with this VALUE as a parameter. I am trying to do something like that: */ 

/* create a macro variable that will store value of "VALUE" column for every observation: */
 call symputx("my_variable", VALUE, 'g');

/* now I would like to pass "my_variable" as a parameter to some macro. &lt;BR /&gt;And that macro should be called for every observation as well: */
 %some_macro(&amp;amp;my_variable.);
&lt;BR /&gt;/* In other words, for every observation I would like to run a macro with a value from some column as a parameter */
run;&lt;/PRE&gt;&lt;P&gt;The first problem is that I can't use macro variable created by call symput in the same data step that it was created. But I don't have any idea, how could I do this &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would be very grateful for any help!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;Filip&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 15:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824168#M325448</guid>
      <dc:creator>filippo_kow</dc:creator>
      <dc:date>2022-07-19T15:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824234#M325484</link>
      <description>&lt;P&gt;&amp;nbsp;Hi again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just realized that I should use call execute routine in the following way:&lt;/P&gt;&lt;PRE&gt;data test;
 set some_data_set;
 call execute('%some_macro('||VALUE||');');
run;&lt;/PRE&gt;&lt;P&gt;But here comes another problem. Let's assume that macro %some_macro does some modifications, comparisons and so on (based on columns from &lt;EM&gt;some_data_set&lt;/EM&gt;), so it looks something like this:&lt;/P&gt;&lt;PRE&gt;%macro some_macro();
 if column_1 &amp;gt; column_2 then do;
  column_3 = 'test';
 end;
/* and so on */
%mend;&lt;/PRE&gt;&lt;P&gt;Unfortunately there is an error message in the log:&amp;nbsp;ERROR 180-322: Statement is not valid or it is used out of proper order.. It looks that I can not use for example comparisons. I totally don't have a clue how can I implement such logic.&amp;nbsp;Any help would be appreciated &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;Best,&lt;/P&gt;&lt;P&gt;&amp;nbsp;Filip&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 20:29:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824234#M325484</guid>
      <dc:creator>filippo_kow</dc:creator>
      <dc:date>2022-07-19T20:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824238#M325487</link>
      <description>&lt;P&gt;There's no way anyone can take this fragmentary piece of the SAS log and make sense out of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, run this line of code to turn on macro debugging.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then run the code again. Show us the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log for this macro, and not selected fragments. (If it's a really long macro, then show us the 50 lines or so before the error). Use the &amp;lt;/&amp;gt; icon and paste the log as text into the window that appears.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Insert Log Icon in SAS Communities.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66171iFEC370B1DBF07B28/image-size/large?v=v2&amp;amp;px=999" role="button" title="Insert Log Icon in SAS Communities.png" alt="Insert Log Icon in SAS Communities.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And from now on, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/428270"&gt;@filippo_kow&lt;/a&gt; please do not show us fragmentary logs, show us the entire log (without us having to ask). Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 21:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824238#M325487</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-19T21:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824240#M325489</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, CALL EXECUTE is a good tool for this.&amp;nbsp; But I'm confused as to what your %SomeMacro is doing.&amp;nbsp; If you code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set some_data_set;
 call execute('%some_macro('||VALUE||');');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SAS code generated by %SomeMacro&amp;nbsp; will execute AFTER the step that writes work.test has completed.&amp;nbsp; &amp;nbsp;Typically, %SomeMacro would generate one or more DATA/PROC steps.&amp;nbsp; But the code generated by the macro cannot is not part of the same step where you invoke CALL EXECUTE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps if you post a little example of what you are trying to do, including work.some_data_set with 3-4 records, and a simple version of %SomeMacro, that will help clarify things.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 21:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824240#M325489</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-07-19T21:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824244#M325491</link>
      <description>&lt;P&gt;First, from what that has been posted in the question, there is no need to convert to create a macro variable and pass it on to another function or macro. If there is something more that what that has been posted please be clear.&lt;/P&gt;
&lt;P&gt;Second, the macro variable will be available after the data step has completed execution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 21:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824244#M325491</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-07-19T21:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824245#M325492</link>
      <description>&lt;P&gt;&amp;nbsp;Hi&amp;nbsp;Paige and Quentin,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In general, I am trying trying to do quite "easy" thing: during processing the dataset take the value from one particular column -&amp;gt; run macro with value of that column as a parameter -&amp;gt; macro should modify other column (based on some conditions).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But step by step:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;This is a sample code that you can run:&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;CODE class=""&gt;options mprint;

/* create input dataset */
data a;
	infile datalines; 
	input name $ value1 value2 value3;
	datalines;
test1 10 1 0
test2 20 22 0
test3 30 3 0
run;

/* re-calculate value3 - set to missing or multiply value2 (passed by parameter in below datastep) by 2 */
%macro do_sth(var);
	if value1 &amp;lt; var then do;
		value3 = .;
	end;
	else do;
		value3 = var * 2;
	end;
%mend;

/* create new dataset with new value3 column */
data b;
	set a;
	call execute('%do_sth('!!value2!!');');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;This is a piece of log after invoking &lt;EM&gt;&lt;STRONG&gt;data b&lt;/STRONG&gt;&lt;/EM&gt;:&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;28         data b;
29         	set a;
30         	call execute('%do_sth('!!value2!!');');
31         run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      30:27   
MPRINT(DO_STH):   if value1 &amp;lt; var then do;
MPRINT(DO_STH):   value3 = .;
MPRINT(DO_STH):   end;
MPRINT(DO_STH):   else do;
MPRINT(DO_STH):   value3 = var * 2;
MPRINT(DO_STH):   end;
MPRINT(DO_STH):   if value1 &amp;lt; var then do;
MPRINT(DO_STH):   value3 = .;
MPRINT(DO_STH):   end;
MPRINT(DO_STH):   else do;
MPRINT(DO_STH):   value3 = var * 2;
2                                                          The SAS System                               15:43 Tuesday, July 19, 2022

MPRINT(DO_STH):   end;
MPRINT(DO_STH):   if value1 &amp;lt; var then do;
MPRINT(DO_STH):   value3 = .;
MPRINT(DO_STH):   end;
MPRINT(DO_STH):   else do;
MPRINT(DO_STH):   value3 = var * 2;
MPRINT(DO_STH):   end;
NOTE: There were 3 observations read from the data set WORK.A.
NOTE: The data set WORK.B has 3 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              671.25k
      OS Memory           27496.00k
      Timestamp           07/19/2022 11:36:05 PM
      Step Count                        37558  Switch Count  2
      

NOTE: CALL EXECUTE generated line.
NOTE: Line generated by the CALL EXECUTE routine.
1         + if value1 &amp;lt; var then do;
            __
            180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the CALL EXECUTE routine.
1         +                            value3 = .;
                                       ______
                                       180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the CALL EXECUTE routine.
1         +                                         end;
                                                    ___
                                                    180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the CALL EXECUTE routine.
1         +                                               else do;
                                                          ____
                                                          180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the CALL EXECUTE routine.
1         +                                                          value3 = var * 2;
                                                                     ______
                                                                     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the CALL EXECUTE routine.
1         +                                                                             end;
                                                                                        ___
3                                                          The SAS System                               15:43 Tuesday, July 19, 2022

                                                                                        180&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;and so on...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need any further clarification, just let me know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;Filip&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 Jul 2022 21:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824245#M325492</guid>
      <dc:creator>filippo_kow</dc:creator>
      <dc:date>2022-07-19T21:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824249#M325495</link>
      <description>&lt;P&gt;CALL EXECUTE runs after the DATA step finishes. The code that CALL EXECUTE generates must be legal valid working SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first line generated by CALL EXECUTE is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if value1 &amp;lt; var then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and this is only valid inside a SAS data step, but remember, the DATA step has finished.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This leads me to ask why don't you just put this code directly into the DATA step? In other words, not inside a macro, not inside CALL EXECUTE. What is it about this code that you haven't told us that makes you think you need a macro (or CALL EXECUTE)? Is your macro %do_sth just a simple example, not the real macro you want to use?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 21:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824249#M325495</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-19T21:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824250#M325496</link>
      <description>&lt;P&gt;Hmm, that's a bad news &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; The code that I placed is just an example - I mean in "real" life I have much more complicated code, but the idea is exactly as in my example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my question is: is it possible in SAS to dynamically (I mean observation by observation) run macro with a column value as a parameter and based on that manipulate other column(s)? From my current knowledge it looks that no matter what you use (&lt;EM&gt;call symput&lt;/EM&gt;, &lt;EM&gt;call execute&lt;/EM&gt;), it runs after the datastep is completed, so there is no solution to my problem...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks in advance!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 22:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824250#M325496</guid>
      <dc:creator>filippo_kow</dc:creator>
      <dc:date>2022-07-19T22:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824251#M325497</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;So my question is: is it possible in SAS to dynamically (I mean observation by observation) run macro with a column value as a parameter and based on that manipulate other column(s)?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can run DATA step code that is dynamic and takes a value in one column and manipulates other columns, and this can change every observation in the data set. You still haven't given a real explanation of why this is not sufficient for you, and why a macro is necessary.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 22:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824251#M325497</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-19T22:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824252#M325498</link>
      <description>Did you consider using ARRAYS instead of a macro?  This feels like a setting where a dynamic array approach might work.&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Jul 2022 22:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824252#M325498</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-07-19T22:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824291#M325521</link>
      <description>&lt;P&gt;&amp;nbsp;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The real example is that I have ca. 15 columns with numerical value. Then, I need to find the minimal one, I am doing it using arrays:&lt;/P&gt;&lt;PRE&gt; lowest_value = &lt;SPAN&gt;min&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;of columns&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;*]);&lt;/SPAN&gt;
 index_lowest_value = whichn&lt;SPAN&gt;(&lt;/SPAN&gt;lowest_value, of columns&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;*]);&lt;/SPAN&gt;
 column_lowest_value = &lt;SPAN&gt;vname&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;columns&lt;SPAN&gt;[&lt;/SPAN&gt;index_lowest_value&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I need to implement some logic for columns other that &lt;EM&gt;column_lowest_value &lt;/EM&gt;(using some loops and so on)&lt;EM&gt;,&lt;/EM&gt; so I try run the macro with &lt;EM&gt;column_lowest_value&lt;/EM&gt; as a parameter - something like that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;call symput('lowest', column_lowest_value, 'g');
%do_sth(&amp;amp;lowest.);

/* or: */
call execute('%do_sth('||lowest||');');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is that I need to do that dynamically, during processing. I am thinking about some workaround, but no idea so far &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 07:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824291#M325521</guid>
      <dc:creator>filippo_kow</dc:creator>
      <dc:date>2022-07-20T07:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824310#M325528</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/428270"&gt;@filippo_kow&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;Hi guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The real example is that I have ca. 15 columns with numerical value. Then, I need to find the minimal one, I am doing it using arrays:&lt;/P&gt;
&lt;PRE&gt; lowest_value = &lt;SPAN&gt;min&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;of columns&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;*]);&lt;/SPAN&gt;
 index_lowest_value = whichn&lt;SPAN&gt;(&lt;/SPAN&gt;lowest_value, of columns&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;*]);&lt;/SPAN&gt;
 column_lowest_value = &lt;SPAN&gt;vname&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;columns&lt;SPAN&gt;[&lt;/SPAN&gt;index_lowest_value&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I need to implement some logic for columns other that &lt;EM&gt;column_lowest_value &lt;/EM&gt;(using some loops and so on)&lt;EM&gt;,&lt;/EM&gt; so I try run the macro with &lt;EM&gt;column_lowest_value&lt;/EM&gt; as a parameter - something like that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;call symput('lowest', column_lowest_value, 'g');
%do_sth(&amp;amp;lowest.);

/* or: */
call execute('%do_sth('||lowest||');');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem is that I need to do that dynamically, during processing. I am thinking about some workaround, but no idea so far &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Don't insert macro-stuff into not fully working sas code, the macro-code will make things more complex, only.&lt;/P&gt;
&lt;P&gt;You should start explaining what you want to achieve at the end, so that we can suggest something working.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 09:25:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824310#M325528</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-07-20T09:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824318#M325533</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/428270"&gt;@filippo_kow&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;Hi guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The real example is that I have ca. 15 columns with numerical value. Then, I need to find the minimal one, I am doing it using arrays:&lt;/P&gt;
&lt;PRE&gt; lowest_value = &lt;SPAN&gt;min&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;of columns&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;*]);&lt;/SPAN&gt;
 index_lowest_value = whichn&lt;SPAN&gt;(&lt;/SPAN&gt;lowest_value, of columns&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;*]);&lt;/SPAN&gt;
 column_lowest_value = &lt;SPAN&gt;vname&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;columns&lt;SPAN&gt;[&lt;/SPAN&gt;index_lowest_value&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I need to implement some logic for columns other that &lt;EM&gt;column_lowest_value &lt;/EM&gt;(using some loops and so on)&lt;EM&gt;,&lt;/EM&gt; so I try run the macro with &lt;EM&gt;column_lowest_value&lt;/EM&gt; as a parameter - something like that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;call symput('lowest', column_lowest_value, 'g');
%do_sth(&amp;amp;lowest.);

/* or: */
call execute('%do_sth('||lowest||');');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem is that I need to do that dynamically, during processing. I am thinking about some workaround, but no idea so far &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can certainly do an array loop, where you tell the loop to not execute if it is the column with lowest value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
input id x1 x2 x3 x4;
cards;
1 5 4 3 2
2 -1 0 1 2
;

data want;
    set example;
    array x x1-x4;
    /* Find lowest value in each row */
    min_value=min(of x{*});
    /* Do things to the columns that don't have min value in each row */
    do i=1 to dim(x);
        if x(i)^=min_value then x(i)=x(i)+1000;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a great example of the &lt;A href="https://xyproblem.info/" target="_self"&gt;XY problem&lt;/A&gt; in action. The user wants to do a somewhat unusual action, and the solution (macros or CALL EXECUTE) has already been determined. This wastes a lot of time, as the simpler solution never gets discussed, and indeed requests to explain the larger problem (that might lead to a simpler solution) go un-answered.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/428270"&gt;@filippo_kow&lt;/a&gt;&amp;nbsp;from now on, please do not force us to repeatedly request an explanation of the problem, and avoid providing that explanation of the problem. From now on, explain the problem at the beginning, rather than saying you need a macro or CALL EXECUTE solution.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 11:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824318#M325533</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-20T11:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824345#M325549</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This still feels like an array problem to me.&amp;nbsp; If Paige's example doesn't help, please post a full DATA step code showing what you are doing.&amp;nbsp; That is, replace the macro call with the SAS code you are hoping the macro would generate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, it's important to know why the code you are trying (with the macro call) cannot work.&amp;nbsp; It's a timing issue essential to understanding the macro language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you submit a DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set some_data_set;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code is is first compiled. During compilation the Program Data Vector is created, and other key things.&amp;nbsp; After it compiles, it is executed During execution it reads data records and processes them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you submit a step that includes a macro call:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set some_data_set;
 %some_macro(&amp;amp;my_variable.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro is executed&amp;nbsp; *before* the DATA step has compiled.&amp;nbsp; The macro language is a pre-processor.&amp;nbsp; It's job is to generate SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus you cannot pass the value of a data step variable to a macro call, because when the macro executes the data step variable does not exist yet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 13:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824345#M325549</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-07-20T13:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro (with a value from column as parameter) for every observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824352#M325554</link>
      <description>&lt;P&gt;If you want to use the distinct values of a variable to generate code there is no need to use the macro language (other than %INCLUDE statement) or CALL EXECUTE().&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Write the code to a file and use %INCLUDE to run it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say you have a macro named FRED that has one input parameter named VALUE.&amp;nbsp; And you have a SAS dataset named HAVE with all of the possible values of VALUE that you need to use with the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set have;
  file code;
  put '%fred(' value= ')' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use that code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the macro generates complete data and/or PROC steps then just run it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the macro generates just some code that could be part of a data step (like IF statements) then include it in the data step where you need it to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set old;
%include code / source2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 13:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-with-a-value-from-column-as-parameter-for-every/m-p/824352#M325554</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-20T13:22:35Z</dc:date>
    </item>
  </channel>
</rss>

