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

I have the following code which takes variables from two datasets and then uses it to form a new table

 

%let msevars=ticker ncusip shrcd exchcd; %let msfvars = prc ret retx shrout cfacpr cfacshr; /* variables from the first dataset */

%include '/wrds/crsp/samples/crspmerge.sas'; /* second dataset*/

%crspmerge(s=m,start=01jan1959,end=30jun2011, sfvars=&msfvars,sevars=&msevars,filters=exchcd in (1,2,3));

 

I have been trying to replicate  the %include statement  for the crspmerge dataset that I have saved in my myfolders like this: 

%include '/folders/myfolders/comp/merged.sas7bdat'; 

 

but I get this error "Maximum level of nesting of macro functions exceeded".

Am I using the statement wrong, if not, is there a different way to do this procedure without using macro variables . I am a noobie in sas so be patient with me 🙂 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Hi, 

 

It looks like crspmerge.sas defines a macro, perhaps https://github.com/jcizel/WRDS-SAS-UTILITIES/blob/master/wrdsmacros/crspmerge.sas or http://people.stern.nyu.edu/jhasbrou/ftp/sasmacros/crspmerge.sas.

 

You are justifiably confused because the comments in the code are wrong:

%include '/wrds/crsp/samples/crspmerge.sas'; /* second dataset*/

The purpose of the %INCLUDE statement is to execute the code in the program crspmerge.sas.  That code does not create a second dataset.  It compiles a macro named crspmerge.  After the macro has been compiled, you can call the macro, and the macro will write some output datasets.  The macro has a number of dependencies that are not clearly defined, for example it expects certain data tables to exist in the directory /wrds/crsp/sasdata/.

 

You should not need to create macro variables in order to use the macro.  In order to use the macro, you need to compile the macro (which means you must run the code in crspmerge.sas).  One way to run that code is to use %INCLUDE.

 

So you should be able to run the macro like:

%include '/wrds/crsp/samples/crspmerge.sas';  /*Execute crspmerge.sas to compile the macro CRSPmerge*/

/*now call the macro*/
%crspmerge(s=m,start=01jan1959,end=30jun2011, sfvars=prc ret retx shrout cfacpr cfacshr,sevars=ticker ncusip shrcd exchcd,filters=exchcd in (1,2,3));

I hope that helps.  Getting started with macros is hard.  And if your first time trying to use a macro is to run a complicated macro like this, written by someone else, and not well-documented, that makes it harder.

 

One suggestion is to turn on options MPRINT and SYMBOLGEN and MLOGIC before you call the macro.  That will write helpful debugging info to your log. 

 

Good Luck.

 

 

 

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

A %INCLUDE statement is for included lines of CODE.  Not a dataset.

 

Having an include followed by a macro call to a macro with same name as the file that was included makes it look like that file just has the MACRO definition. I would be surprised if that file had any code that defined any datasets.

ballardw
Super User

Do you mean that you are attempting to USE the data set? Or something else, if so what?

Quentin
Super User

Hi, 

 

It looks like crspmerge.sas defines a macro, perhaps https://github.com/jcizel/WRDS-SAS-UTILITIES/blob/master/wrdsmacros/crspmerge.sas or http://people.stern.nyu.edu/jhasbrou/ftp/sasmacros/crspmerge.sas.

 

You are justifiably confused because the comments in the code are wrong:

%include '/wrds/crsp/samples/crspmerge.sas'; /* second dataset*/

The purpose of the %INCLUDE statement is to execute the code in the program crspmerge.sas.  That code does not create a second dataset.  It compiles a macro named crspmerge.  After the macro has been compiled, you can call the macro, and the macro will write some output datasets.  The macro has a number of dependencies that are not clearly defined, for example it expects certain data tables to exist in the directory /wrds/crsp/sasdata/.

 

You should not need to create macro variables in order to use the macro.  In order to use the macro, you need to compile the macro (which means you must run the code in crspmerge.sas).  One way to run that code is to use %INCLUDE.

 

So you should be able to run the macro like:

%include '/wrds/crsp/samples/crspmerge.sas';  /*Execute crspmerge.sas to compile the macro CRSPmerge*/

/*now call the macro*/
%crspmerge(s=m,start=01jan1959,end=30jun2011, sfvars=prc ret retx shrout cfacpr cfacshr,sevars=ticker ncusip shrcd exchcd,filters=exchcd in (1,2,3));

I hope that helps.  Getting started with macros is hard.  And if your first time trying to use a macro is to run a complicated macro like this, written by someone else, and not well-documented, that makes it harder.

 

One suggestion is to turn on options MPRINT and SYMBOLGEN and MLOGIC before you call the macro.  That will write helpful debugging info to your log. 

 

Good Luck.

 

 

 

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 987 views
  • 4 likes
  • 4 in conversation