BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
constliv
Obsidian | Level 7

Hi,

I'm using EG 5.1  .

 

I've written a few macros, each with several parameters. Now, when I calll the macros from different programs I find I don't verbatim remember the parameters for each macro and their position.

 

I noticed that in the program where I created the macros, I could insert comments which appear as pop-up help text when the macro is invoked. But outside that particular program that help does not appear. E.g in below macro the text "libname without quotes e.g. source" appears as a pop-up when the macro is invoked, BUT only in the same program where the macro is written. If I invoke it from a different program in the same project, then no pop-up appears.

 

%macro dir (libname /*libname without quotes e.g. source*/);
	TITLE 'Directory listing for library ' %upcase("&libname") ;

	PROC SQL;
		select libname ,
			memname,
			memlabel,
			nobs,
			nvar,
			modate

		FROM DICTIONARY.TABLES
			WHERE LIBNAME = %upcase( "&libname" ) 
				ORDER BY modate desc;
	QUIT
	;
	TITLE;
%mend dir;


 

Any ideas apprecited.

1 ACCEPTED SOLUTION

Accepted Solutions
constliv
Obsidian | Level 7

RW9,

 

Thank you very much for the helpful inputs. Valuable.

 

Your idea on Base SAS Abbreviations pointed me to exactly what I'm looking for.

 

In SAS EG 5.1  I found there's a feature Program > Add Abbrevation Macro that fully resolves my issue.  And Program > Editor Macros is very handy to list out all macros put under Add Abbreviation Macro

 

Thanks.

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, first off, this is where named parameters should really be used.  Named parameters such as:

%macro temp (in_file=,out_file=);

Then have some descriptive to tell you what they are, and positioning on the call does not matter as you could call the above:

%temp (in_file=abc,out_file=def);

Or

%temp (out_file=def,in_file=abc);

 Next off, its really not a good idea to use SAS reserved words, like libname, as parameters (or macro variables, or variable names, or anything else).  Just look at the color of your code, it recognises that as a reserved keyword.

 

Next, try using some sort of consistent casing in the code, it will make it far more readable.

 

And you can use Base SAS functions to reduce code, for instance:

%macro dir (lib=);

  title "Directory listing for Library: %upcase(&lib.)";

  proc print data=sashelp.vtables;
    var libname memlabel nobs nvar modate;
    where libname=upcase("&lib.");
  run;

%mend dir;

Also, if your writing a generalised macro, then you would have a user guide, some sort of testing document etc. so the user could refer to these for help?

 

And finally, you can setup in Base SAS Abbreviations which can pre-populate text for you - although I really don't find those helpful.  I am afraid an editor such as Visual Studio where code completion tips pop up is not in SAS releases (at least the ones I have used).  

constliv
Obsidian | Level 7

RW9,

 

Thank you very much for the helpful inputs. Valuable.

 

Your idea on Base SAS Abbreviations pointed me to exactly what I'm looking for.

 

In SAS EG 5.1  I found there's a feature Program > Add Abbrevation Macro that fully resolves my issue.  And Program > Editor Macros is very handy to list out all macros put under Add Abbreviation Macro

 

Thanks.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 1747 views
  • 0 likes
  • 2 in conversation