handout_sas_09_SAS_Macro

Here are the data 287 287 274 174 174 174 347 287 287

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a file with information about every order they receive. For each order, the data include the customer ID number, date the order was placed, model name, and quantity ordered. Here are the data: 287 287 274 174 174 174 347 287 287 15OCT03 15OCT03 16OCT03 17OCT03 17OCT03 17OCT03 18OCT03 21OCT03 21OCT03 Delta Breeze Santa Ana Jet Stream Santa Ana Nor'easter Scirocco Mistral Delta Breeze Santa Ana 15 15 1 20 5 1 1 30 25 This DATA step reads the raw data from a file named Orders.dat creating a SAS data set named ORDERS. DATA orders; INFILE 'c:\MyRawData\Orders.dat'; INPUT CustomerID $ 1-3 OrderDate DATE7. Model $ 13-24 Quantity; RUN; Every Monday the president of the company wants a detail-level report showing all the current orders. On Friday the president wants a report summarized by customer. You could write two separate programs to run these reports, or you could write one program using macros. Combining conditional logic with the automatic variable &SYSDAY, the following program creates a macro named REPORTS that prints a detail report if you run it on Monday, and a summary report if you run it on Friday (and no report on other days). 9 SUGI 29 Tutorials %MACRO reports; %IF &SYSDAY = Monday %THEN %DO; PROC PRINT DATA = orders NOOBS; FORMAT OrderDate DATE7.; TITLE "&SYSDAY Report: Current Orders"; %END; %ELSE %IF &SYSDAY = Friday %THEN %DO; PROC TABULATE DATA = orders; CLASS CustomerID; VAR Quantity; TABLE CustomerID ALL, Quantity; TITLE "&SYSDAY Report: Summary of Orders"; %END; %MEND reports; RUN; %reports RUN; If you run this program on Monday, the macro processor with generate the following standard SAS code. PROC PRINT DATA = orders NOOBS; FORMAT OrderDate DATE7.; TITLE "Monday Report: Current Orders"; And the output will look like this: Monday Report: Current Orders Customer ID 287 287 274 174 174 174 347 287 287 Order Date 15OCT03 15OCT03 16OCT03 17OCT03 17OCT03 17OCT03 18OCT03 21OCT03 21OCT03 Model Delta Breeze...
View Full Document

This note was uploaded on 03/21/2013 for the course AMS 597 taught by Professor Xing during the Spring '11 term at SUNY Stony Brook.

Ask a homework question - tutors are online