sas-macro

In SAS, outside of a data step, what is the best way to replace a character in a macro variable with a blank?

It seems that TRANSLATE would be a good function to use. However when using %SYSFUNC with this function, the parameters are not surrounded with quotes. How do you indicate a blank should be used as replacement? ...

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

In my code I have several macros. Macro A is the main macro. Macro A then calls macro B which in turn calls macro C. In SAS, do I have to define them in backwards order? In other words, do I have to define macro C first, then macro B, then macro A last? Or does it matter since SAS reads all the code in before it actually hits the ...

SAS Macro GLOBAL scope

is there a short way to make ALL macro variables created inside a macro global in scope? ie: %macro x; %global _all_; * ??? ; %let x=1; %let y=1; %let z=1; %mend; ...

submit SAS code or macro from Toolbar

Is it possible to allocate a SAS script or macro to a Toolbar button in Base SAS? ie can you 'dm' a macro or sas script? ...

How do you assign the result of a macro function to a macro variable in SAS?

I have a macro that creates a timestamp (to append to output file names). However, rather than have to remember what macro variable the macro assigns the value to, I would prefer to assign a macro variable to the result of the macro (if that isn't circular enough). %let tms= %tms(); This is the current macro.... %macro tms ; %* C...

Referencing a remote SAS work library from another session

Ever had a problem with a SAS session, but been unable to close the session due to having critical files in your remote work library (RWORK)?? I certainly have! So how do you access that library from another (new) session? ...

Can I change the execution order of the CALL EXECUTE stack in SAS?

I'm using SAS 9.1.3 to call a macro in a DATA step, but the macro generates a PROC REPORT step, so I am using CALL EXECUTE to call it, generate all those PROC REPORT steps, and then execute them all after the DATA step. I'm using an array, and the macro is executed each time for every element in this array: DATA macro_test; ARRAY que...

Using SAS Macro to pipe a list of filenames from a Windows directory

I am trying to amend the macro below to accept a macro parameter as the 'location' argument for a dir command. However I cannot get it to resolve correctly due to the nested quotes issue. Using %str(%') does not work, neither do quoting functions for some reason. The macro will work fine when the filepath has no spaces (eg C:\temp\wit...

sas macro index or other?

I have 169 towns for which I want to iterate a macro. I need the output files to be saved using the town-name (rather than a town-code). I have a dataset (TOWN) with town-code and town-name. Is it possible to have a %let statement that is set to the town-name for each iteration where i=town-code? I know that I can list out the town-...

SAS macro include guards

In other programming languages such as C++, include guards are used to prevent multiple inclusions of the same code. Like this in C++: #ifndef FOO_INCLUDED #define FOO_INCLUDED .... #endif Does it make sense to build inclusion guards into your SAS macro function definitions? And how should it be done? ...

Retrieving SAS macro from a catalog

Can anyone provide the syntax for retrieving a SAS Macro from a permanent catalog? (ie copy it into my work.sasmacr location) I don't need this as part of my autocall as I won't always be connecting to this library... ...

SAS Enterprise Guide DROPDOWN menus

Is it possible to create customised dropdown menus in EG? ie I would like to present a user with a list of dropdowns, and the ability to click a 'submit' button that would use the values of those dropdowns to run a SAS macro... Also, is this possible without setting up a stored process? ...

clearing a library which is being used for stored compiled SAS macro

I have a program which creates a stored compiled macro in a library using the syntax: options mstored sasmstore=MyLib; %macro MyMac() /store source des='My Macro'; %let x=1; %mend; However I cannot seem to re-assign my library (MyLib) afterwards - I get the following message (sas 9.1.3): ERROR: Unable to clear or re-assign the li...

Regex to convert a space separated list to a SQL where clause

I'm almost embarassed, but I'm struggling to create a regular expression to change something like cat dog mouse to a SQL where clause: a.cat=b.cat AND a.dog=b.dog AND a.mouse=b.mouse With s/(\w*)\s?/a.$1=b.$1 AND / I get a.cat=b.cat AND a.dog=b.dog AND a.mouse=b.mouse AND a.=b. AND Ouch. Help appreciated. EDIT: I ended up usin...

sas macro -tofind vintage

how to find vintage in risk management with sas macro? ...