hi all
i am trying to learn more about macros and this below is the 1st problem i was doing:
When i run the code i do see in the logs that a data set gets created but it dont get the output so i figure it is something with the macro code but dont know what.
Also eventhough i have the mprint option i still dont see in the logs that the macro processor resolves the sas statements and that is probabloy cuz something's wrong with the macro code?
Please help
options mprint;
DATA orders;
INPUT CustomerID $ 1-3 OrderDate DATE7. Model $ 13-24 Quantity;
cards;
287 15OCT03 Delta Breeze 15
287 15OCT03 Santa Ana 15
274 16OCT03 Jet Stream 1
174 17OCT03 Santa Ana 20
174 17OCT03 Nor'easter 5
174 17OCT03 Scirocco 1
347 18OCT03 Mistral 1
287 21OCT03 Delta Breeze30
287 21OCT03 Santa Ana 25
;run;
%macro reports;
%if &sysday=Monday %then proc print data=orders;
%else %if &sysdate=02apr13 %then %do;proc sort data=orders;by customerid; proc print data=orders; by customerid;%end;
%mend;run;
%reports
run;
You are having semi-colon issues.
1) The semicolon after the first PROC PRINT will end the %THEN clause and not the proc print.
2) You need something to let SAS know that you are done specifying the inputs to the macro call. So add a semi-colon to the line where %reports is executed.
Also be careful in your comparisons. Case matters.
If you get more consistent in your formatting you can avoid this confusion and also eliminate the randomly placed RUN; statements.
%macro reports;
%if (&sysday=Monday) %then do;
proc print data=orders;
run;
%end;
%else %if (&sysdate9=02APR2013) %then %do;
proc sort data=orders;
by customerid;
run;
proc print data=orders;
by customerid;
run;
%end;
%mend;
%reports;
Some things to check:
1. Comparisons are case sensitive so are the cases for sysday and sysdate the same as you'd see in the macro variables?
2. Rather than have any proc's in the then clauses you can add some %put statements to test your logic is flowing the way you want.
3. Add in another else to deal with when neither of the first two options are met, usually for error checking.
Tweak the code until you get what you expect then add in your procs.
Here's an example.
%macro reports;
%if &sysday=Monday %then %put Monday Run;
%else %if &sysdate=02apr13 %then %do;
%put Otherwise clause;
%end;
%else %do;
%put WARNING: Other else clause - check code;
%end;
%mend;
%reports;
so it turns that 02APR13 instead of 02apr13 made a big change.Is that what you mean by Comparisons are case sensitive?
cuz now with 02APR13 i see the output.
Thanks guys
yes, case is important
%put note: SysDate &SysDate;
%put note: SysDate9 &SysDate9;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.