Search notes:

SAS: Interaction between macros and data steps with execute, symget and symput

With execute, symput and symget, it is possible to interact betweend macros and data steps.
%let macroVar = 1;
%let time_0  = %sysfunc(time());

%macro incr_macroVar;
  %let macroVar=%eval(&macroVar+1);
  %local t_now  t_diff;
  %let   t_now  = %sysfunc(time()); 
  %let   t_diff = %sysevalf(&t_now - &time_0);

  %put macroVar = &macroVar, seconds past start: %sysfunc(putn(&t_diff, 3.1));
%mend;


data _null_;

  call sleep(1.3, 1);

  macroVar = symget('macroVar');   
  put 'macroVar as per symget: ' macroVar; /* macroVar as per symget: 1             */
  put 'going to execute %incr_macroVar';   /* going to execute %incr_macroVar       */
  call execute('%incr_macroVar');          /* macroVar = 2, seconds past start: 1.3 */
                                           /*                                       */
  call sleep(1.3, 1);                      /*                                       */
  put ' ';                                 /*                                       */
                                           /*                                       */
  macroVar = symget('macroVar');           /*                                       */ 
  put 'macroVar as per symget: ' macroVar; /* macroVar as per symget: 2             */
  call symput('macroVar', macroVar +5);
  put 'going to execute %incr_macroVar';   /* going to execute %incr_macroVar       */
  call execute('%incr_macroVar');          /* macroVar = 8, seconds past start: 2.6 */

run;
Github repository about-SAS, path: /programming/call-routines/execute/interaction-macro-datastep.sas

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Companie...', 1745582383, '3.149.246.106', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Companies-Products/SAS/programming/call-routines/execute/interaction-macro-datastep(67): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78