DATA Step, Macro, Functions and more

How to find a macro using name

Reply
New Contributor
Posts: 4

How to find a macro using name

Hello, I have a SQL-code with connection to Teradata. Incide this code SAS macro - %month_diff_td. How can I view (and change) the code?

I use %copy

%copy MONTHS_DIFF_TD() / SOURCE;

but it doesn't help:

 

 

14         GOPTIONS ACCESSIBLE;
ERROR: This combination of default and specified %COPY statement options is not supported.
ERROR: An error occurred during the execution of the %COPY statement.
15         %copy MONTHS_DIFF_TD() / SOURCE;
                                _
                                180

ERROR 180-322: Statement is not valid or it is used out of proper order.

May be I can use some fing tool using macro name?

 

Super User
Super User
Posts: 7,942

Re: How to find a macro using name

[ Edited ]
Posted in reply to IvchenkoMariya

Look at the source code which created the macro?  If you don't have the source code and only have the compiled catalog then that should work, unless of course the catalog is set to protect the contents - one thing which I detest in programming.  This is why I strongly advise against the use of catalogs in any sense as the whole 32/64bit debacle has proved.

 

Oh, and you don't specify ():

http://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#p0oltlodtnemugn10...

 

Should read:

%copy MONTHS_DIFF_TD/SOURCE;

Assuming months_diff_td is the correct name of the macro. 

New Contributor
Posts: 4

Re: How to find a macro using name

When I drop "()" I have error

ERROR: Macro MONTHS_DIFF_TD not found in libref MAMACRO.

ERROR: An error occurred during the execution of the %COPY statement.

 

Macro is exist! I found in by hands (running over all folders)

%macro MONTHS_DIFF_TD(date1,date2);
		cast(((&date2 - &date1) month(3)) as integer )
%mend;
Super User
Posts: 19,772

Re: How to find a macro using name

Posted in reply to IvchenkoMariya

%COPY doesn't search your folders, it only works if the macro is already compiled and stored somewhere in your SAS system already. 

New Contributor
Posts: 4

Re: How to find a macro using name

Ok, Copy
New Contributor
Posts: 4

Re: How to find a macro using name

Ok, %Copy can't solve my problem. Maybe somebody know a way How to fing a macro in Explorer window

Super User
Super User
Posts: 7,942

Re: How to find a macro using name

Posted in reply to IvchenkoMariya

Well

- You can check your autoexec.sas (or other startup files) and see if there is an:

options sasautos=...;

Statement there - that is the first place SAS looks for them.

 

- Then your programs could include further ones or define them - so look at your startup files, and any other programs you run.

 

- Finally, there is the proc scaproc procedure, which does some code analyzing, you start it before your run, then after to get some results - however this might not capture everything if they are set in start programs.

 

i suppose the question at the end of the day is why you don't know where the macros are, I mean to be able to use macros you should know something about them.  I know most don't bother, but properly developed code should have user guides, testing and such like that you should be aware of before using them, much like any software development.

Super User
Posts: 7,768

Re: How to find a macro using name

Posted in reply to IvchenkoMariya

You seem to misunderstand what the macro statement %copy does.

Look at the documentation here: %COPY Statement

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 7 replies
  • 335 views
  • 2 likes
  • 4 in conversation