SAS: Calling one macro from another...Order of Macro Definitions

314

Solution 1

First, you must define a macro before it is called.

Second, it doesn't matter where the macro is invoked as long as you have loaded it before-hand.

To elaborate on your issue: The autocall library is your friend. If you SAS administrator won't allow you to put your macros in the autocall library, you can append the autocall like so:

filename mymacros 'c:\mysas'; 
/*this defines the directory you have stored your macros*/

options sasautos=(sasautos mymacros) mautosource; 

Solution 2

a macro has to be defined before it is called. for performance reasons, it is best not to define a macro inside another -- if you do so, then it will be re-defined every time you call the outer macro. the following works fine:

%macro a;
  %put a;
  %b
%mend a;

%macro b;
  %put b;
  %c
%mend b;

%macro c;
  %put c;
%mend c;

%*-- %a is main --*;
%a
/* on log
a
b
c
*/

Solution 3

You must define a macro before it is called, so the line with "%A" would need to follow the definition of macro A. The order of the other macro definitions does not matter, as long as they are defined before they are called. Typically in my programs I set up a main macro like you describe, then the last line of the program calls this macro.

Another option to consider is to set up a macro autocall library, which contains the definitions of many macros. This works best for reusable macros, so that you do not have to redefine them in each program.

Share:
314
Lisandro
Author by

Lisandro

Updated on May 27, 2020

Comments

  • Lisandro
    Lisandro almost 4 years

    I am in the midst of figuring out if there are other methods/techniques on how you can fit a background video that has large aspect ratios to be seen in full on landing page without getting cropped. Right now, the only solution i have found was to add object-fit:cover to the video element. It did the trick. However, its not compatible to Internet explorer. The true aspect ratio of the video I'm using is 3840X2160. I already tried adding width and height property in viewport to the parent element but it didn't work.

    Below is my current code.

    HTML

    <div class="v-header container">
        <div class="fullscreen-video-wrap"> 
            <video src="video1.mp4" autoplay muted loop></video>
        </div>
    </div>  
    

    CURRENT CSS

    .fullscreen-video-wrap video{
    
    position: absolute;
    min-width: 100%;
    min-height: 100%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index:-1;
    
    }
    

    PREVIOUS CSS CODE WITH SOLUTION with object-fit:cover

    .fullscreen-video-wrap video{
    position:absolute;
    top:0;
    left: 0;
    width:100%;
    height:100%;
    z-index: -1;
    object-fit: cover;          
    }
    
    • Pete
      Pete over 5 years
      have you tried max-width and height instead of min? The only browser object fit is not compatible with is ie and you should be able to get a polyfill for it
    • Lisandro
      Lisandro over 5 years
      yes i did try those but was unable to get what i wanted as i got a white spaces/spaces around the video when resizing to smaller screens.
    • Pete
      Pete over 5 years
      but if the aspect ratio of the screen doesn't match the video aspect ratio then I don't think it will fill the screen
    • Lisandro
      Lisandro over 5 years
      for smaller videos you can stretch them, idk what else to do if video is supposed to be larger than the native resolution of your screen monitor. is there a fix for the object-fit cover to work in ie?
  • Robert Penridge
    Robert Penridge almost 9 years
    Technically speaking, the autocall library does not load macros 'before-hand'. If the user tries to execute a macro and that macro has not already been defined, then SAS will begin to look for it in the autocall library. If it successfully finds a filename that matches the call, and that file contains a macro name that matches the call, only then will it compile the macro. If you then make changes to that file in the autocall library you will need to resubmit the code manually for those changes to become available in an interactive SAS session.
  • Lisandro
    Lisandro over 5 years
    this works!one problem though on my code. i had container with max-width and this was messing up your solution. i removed it and everything went fine.