BookmarkSubscribeRSS Feed
Paari
Calcite | Level 5

%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;

4 REPLIES 4
RichardinOz
Quartz | Level 8

|| 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

mohamed_zaki
Barite | Level 11

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.

LinusH
Tourmaline | Level 20

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 624 views
  • 0 likes
  • 5 in conversation