Can anybody explain me why we use '||' in call %execute() routine?? below is the given problem

Reply
Occasional Contributor
Posts: 16

Can anybody explain me why we use '||' in call %execute() routine?? below is the given problem

%macro rept(dat,a,dsn);

   proc chart data=&dsn;

       title "Chart for &dat";

       where(date="&dat");

       vbar &a;

   run;

%mend rept;

data _null_;

   set dates;

   call execute('%rept('||date||','||'var1,reptdata)'); /* here is use of pipe that I need to know */

run;

Respected Advisor
Posts: 3,788

Re: Can anybody explain me why we use '||' in call %execute() routine?? below is the given problem

Super Contributor
Posts: 644

Re: Can anybody explain me why we use '||' in call %execute() routine?? below is the given problem

|| is the concatenation operator in SAS.  In Excel you would use &.

Call execute(<code to be executed>) allows SAS to place a section of code into the program flow to be executed immediately after the data step concludes.  In this case the code to be executed is a macro rept which is intended to draw a vbar chart on var1 for a given date drawing data from the reptdata table.  The data _null_ step is intended to provide the date parameter from a table called dates.  Lets say the date, being numeric, has the unformatted value 12345 (I have no idea what date that is).  Then the code inserted into the program flow should be

      %rept(12345,var1,reptdata)

To get this result the data _null_ step has to join some constant text values: %rept(   and then later   ,var1,reptdata)   with the date value 12345 taken from the dates table in the middle.  The expression could be simplified as

     call execute('%rept('  ||date||  ', var1, reptdata)');  /* spaces added for clarity */

since apparently for this example var1 from reptdata is always used when table dates is used as the source of date data.

Richard

Super Contributor
Posts: 490

Re: Can anybody explain me why we use '||' in call %execute() routine?? below is the given problem

As Stated in

CALL EXECUTE Routine

to generate a macro invocation whose parameter is the value of the variable resolved by the DATA step to a macro text expression or a SAS statement.

Super User
Posts: 5,386

Re: Can anybody explain me why we use '||' in call %execute() routine?? below is the given problem

If you like, you could use the cats() function instead, which will give you commas instead of the double pipes.

A bit more readable if you ask me

Data never sleeps
Ask a Question
Discussion stats
  • 4 replies
  • 223 views
  • 0 likes
  • 5 in conversation