<?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: How to CALL EXECUTE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/758018#M239305</link>
    <description>&lt;P&gt;Have you already run my code?&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jul 2021 09:51:01 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-07-29T09:51:01Z</dc:date>
    <item>
      <title>How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757601#M239161</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds;
set sashelp.class;
run;

data ds1;
set sashelp.class;
run;

data ds2;
set sashelp.class;
run;



data _null_;
set sashelp.vtable;
where libname = upcase("&amp;amp;lib.");
call execute( "proc sort data=&amp;amp;lib.." !! strip(memname) !! ";
              by &amp;amp;sortvar.;
              run; ");
run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;suppose common variable age sort how to call the macro variable&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 07:44:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757601#M239161</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2021-07-28T07:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757606#M239164</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* clean up first */
proc datasets lib=work kill;
quit;

data ds;
set sashelp.class;
run;

data ds1;
set sashelp.class;
run;

data ds2;
set sashelp.class;
run;

%let lib=WORK;
%let sortvar=age;

data _null_;
set sashelp.vtable;
where libname = upcase("&amp;amp;lib.");
call execute( "proc sort data=&amp;amp;lib.." !! strip(memname) !! ";
              by &amp;amp;sortvar.;
              run; ");
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to make this a macro, add the proper definition statements around your code, and call the macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro sort_all(lib=,sortvar=);

data _null_;
set sashelp.vtable;
where libname = upcase("&amp;amp;lib.");
call execute( "proc sort data=&amp;amp;lib.." !! strip(memname) !! ";
              by &amp;amp;sortvar.;
              run; ");
run;

%mend;

%sort_all(lib=work,sortvar=age)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jul 2021 07:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757606#M239164</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-28T07:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757628#M239175</link>
      <description>&lt;P&gt;Not clear (at least for me) what you are trying to achieve in the long run. Can you explain what you expect as result?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 09:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757628#M239175</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-07-28T09:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757656#M239185</link>
      <description>&lt;P&gt;sort all datasets by common variable&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 11:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757656#M239185</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2021-07-28T11:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757660#M239186</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/390518"&gt;@pavank&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;sort all datasets by common variable&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thanks. Looking at the code suggest by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, i don't see potential for optimization.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 12:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757660#M239186</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-07-28T12:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757677#M239191</link>
      <description>&lt;P&gt;I don't understand what your question is.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;suppose common variable age sort how to call the macro variable&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The code you posted was using the macro variable SORTVAR.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To assign a value to that macro variable you can use %LET statement.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sortvar=age;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;If that was not your question&amp;nbsp;then please try re-phrasing the question&amp;nbsp;to make it clearer.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 12:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757677#M239191</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-28T12:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757722#M239209</link>
      <description>&lt;P&gt;A really good idea when using CALL EXECUTE is to create the code in a string first and then pass that to CALL EXECUTE. This way you can check if the string is being generated correctly before using CALL EXECUTE. I also recommend using CATT() and putting each portion on a separate line.&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;already indicated, you also need to declare your macro variable ahead of time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds;
set sashelp.class;
run;

data ds1;
set sashelp.class;
run;

data ds2;
set sashelp.class;
run;

%let sortVar = Age;

data _null_;
set sashelp.vtable;
where libname = upcase("&amp;amp;lib.");
*I put each portion of the string on a separate line to make it easy to ensure quotes, commas and parenthesis are correctly specified;
str = CATT( "proc sort data=&amp;amp;lib.." ,
                      strip(memname),
                      "; by &amp;amp;sortvar.; run; "
                 );
call execute(str);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Some references that may be helpful:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;UCLA introductory tutorial on macro variables and macros&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Tutorial on converting a working program to a macro &amp;lt;- typically if you follow these steps in your development your code will almost always be correct and working.&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Examples of common macro usage&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/390518"&gt;@pavank&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds;
set sashelp.class;
run;

data ds1;
set sashelp.class;
run;

data ds2;
set sashelp.class;
run;



data _null_;
set sashelp.vtable;
where libname = upcase("&amp;amp;lib.");
call execute( "proc sort data=&amp;amp;lib.." !! strip(memname) !! ";
              by &amp;amp;sortvar.;
              run; ");
run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;suppose common variable age sort how to call the macro variable&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 14:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/757722#M239209</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-28T14:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/758012#M239303</link>
      <description>&lt;P&gt;For sort all datasets pre request it must be common variable and we can not sort all datasets without common variable in a library&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 09:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/758012#M239303</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2021-07-29T09:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/758018#M239305</link>
      <description>&lt;P&gt;Have you already run my code?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 09:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/758018#M239305</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-29T09:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/758022#M239307</link>
      <description>&lt;P&gt;yes i did&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 09:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/758022#M239307</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2021-07-29T09:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/758036#M239318</link>
      <description>&lt;P&gt;So you have your solution.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 10:41:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CALL-EXECUTE/m-p/758036#M239318</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-29T10:41:50Z</dc:date>
    </item>
  </channel>
</rss>

