DATA Step, Macro, Functions and more

2 "sub-macros" work, but I'm having trouble combining them...

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

2 "sub-macros" work, but I'm having trouble combining them...

So, the following two macros work:

--To return a specified number of observations, this one works properly

%macro homework3_3 (obs=);

     options nodate nonumber;

     title "LISTING PRODUCED ON: &sysday, &sysdate9. at &systime";

     proc print data=hw3c.stocks (obs=&obs);

     run;

%mend homework3_3;

%homework3_3 (obs=5);

--To return values within a date range, and it works properly as well

%macro daterange(begindate,enddate);

     %let begindate = "&begindate"d;

     %let enddate = "&enddate"d;

     proc print data=hw3c.stocks;

     where date between &begindate and &enddate;

     run;

%mend daterange;

%daterange(05Jan2013,20Jan2013)

However, when I combine these macros with the code below:

%macro PRINT_N(begindate,enddate,obs=);

     %let begindate = "&begindate"d;

     %let enddate = "&enddate"d;

     proc print data=hw3c.stocks (obs=&obs);

     where date between &begindate and &enddate;

     run;

     %mend PRINT_N;

%daterange(05Jan2013,20Jan2013,obs=5)

I get an error message: "ERROR: The keyword parameter OBS was not defined with the macro."  I don't understand why, because I defined OBS in the same way in both this Macro and in the first Macro; it worked in Macro #1 but not in Macro #3.  What am I doing wrong?  Thanks!

Matt


Accepted Solutions
Solution
‎02-22-2013 05:44 PM
Super Contributor
Posts: 1,636

Re: 2 "sub-macros" work, but I'm having trouble combining them...

Hi

changing

%daterange(05Jan2013,20Jan2013,obs=5)

to

%print_n(05Jan2013,20Jan2013,obs=5)

View solution in original post


All Replies
Solution
‎02-22-2013 05:44 PM
Super Contributor
Posts: 1,636

Re: 2 "sub-macros" work, but I'm having trouble combining them...

Hi

changing

%daterange(05Jan2013,20Jan2013,obs=5)

to

%print_n(05Jan2013,20Jan2013,obs=5)

New Contributor
Posts: 2

Re: 2 "sub-macros" work, but I'm having trouble combining them...

Wow.  That's embarrassing.  Thank you!  (Feels rather silly to make a mistake like that!)

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 173 views
  • 0 likes
  • 2 in conversation