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
Hi
changing
%daterange(05Jan2013,20Jan2013,obs=5)
to
%print_n(05Jan2013,20Jan2013,obs=5)
Hi
changing
%daterange(05Jan2013,20Jan2013,obs=5)
to
%print_n(05Jan2013,20Jan2013,obs=5)
Wow. That's embarrassing. Thank you! (Feels rather silly to make a mistake like that!)
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.