04-02-2013 03:38 PM
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?
INPUT CustomerID $ 1-3 OrderDate DATE7. Model $ 13-24 Quantity;
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
%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;
04-02-2013 03:51 PM
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.
%if (&sysday=Monday) %then do;
proc print data=orders;
%else %if (&sysdate9=02APR2013) %then %do;
proc sort data=orders;
proc print data=orders;
04-02-2013 03:56 PM
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.
%if &sysday=Monday %then %put Monday Run;
%else %if &sysdate=02apr13 %then %do;
%put Otherwise clause;
%put WARNING: Other else clause - check code;
04-02-2013 05:05 PM
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.