1 / 14

SAS Macro Language

SAS Macro Language. Write and debug SAS program without macro coding. Generalize by replacing hard coded values with macro variable references. Create a macro definition with macro parameters. Add macro level programming for conditional and iterative processing.

keough
Download Presentation

SAS Macro Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SAS Macro Language

  2. Write and debug SAS program without macro coding Generalize by replacing hard coded values with macro variable references Create a macro definition with macro parameters Add macro level programming for conditional and iterative processing Add data driven customization

  3. Marketing Data region city product sales revenue Northeast New York sedan 400 100 Northeast Boston coupe 800 200 Midwest Chicago minivan 200 50 Midwest Detroit suv 100 25 Northwest Seattle sedan 600 150 Northwest Boise coupe 20 5 Southeast Raleigh minivan 200 50 Southeast Atlanta suv 400 100 Southwest Dallas sedan 1000 250 Southwest Houston coupe 2000 500

  4. Write and debug SAS program without macro coding proc sort data=lib1.marketing (where=(region="Northeast")) out=sales; by city product; run; title1 "Sales Report for Northeast Region"; proc print data=sales noobs; var city product sales revenue; run;

  5. Write and debug SAS program without macro coding Sales Report for Northeast Region city product sales revenue Boston coupe 800 200 New York sedan 400 100

  6. Generalize by replacing hard coded values with macro variable references %let region = Northeast; %let sortvar = city product; proc sort data=lib1.marketing (where=(region="&region")) out=sales; by &sortvar; run; title1 "Sales Report for &region Region"; proc print data=sales noobs; var &sortvar sales revenue; run; %put region=&region sortvar=&sortvar;

  7. Generalize by replacing hard coded values with macro variable references Sales Report for Northeast Region city product sales revenue Boston coupe 800 200 New York sedan 400 100

  8. Create a macro definition with macro parameters %macro sales (region=, sortvar=city product); proc sort data=lib1.marketing (where=(region="&region")) out=sales; by &sortvar; run; title1 "Sales Report for &region Region"; proc print data=sales noobs; var &sortvar sales revenue; run; %put region=&region sortvar=&sortvar; %mend sales; %sales (region=Northeast);

  9. Create a macro definition with macro parameters Sales Report for Northeast Region city product sales revenue Boston coupe 800 200 New York sedan 400 100

  10. Add macro level programming for conditional and iterative processing %macro sales (region=, sortvar=city product) / minoperator; %let reglist = Northeast Midwest Northwest Southeast Southwest; %if &region in &reglist %then %do; proc sort data=lib1.marketing (where=(region="&region")) out=sales; by &sortvar; run; title1 "Sales Report for &region Region"; proc print data = sales noobs; var &sortvar sales revenue; run; %end; %else %put Invalid value for region=&region; %mend sales; %sales (region=Northeast);

  11. Add macro level programming for conditional and iterative processing Sales Report for Northeast Region city product sales revenue Boston coupe 800 200 New York sedan 400 100

  12. Add data driven customization %macro sales (region=,sortvar=city product) / minoperator; proc sql noprint; select distinct region into :reglist separated by " " from lib1.marketing; quit; %put reglist=&reglist; %if &region in &reglist %then %do; proc sort data=lib1.marketing (where=(region="&region")) out=sales; by &sortvar; title1 "Sales Report for &region Region"; proc print data = sales noobs; var &sortvar sales revenue; run; %end; %else %put No customers on file from region=&region; %mend sales; %sales (region=Northeast);

  13. Add data driven customization Sales Report for Northeast Region city product sales revenue Boston coupe 800 200 New York sedan 400 100

  14. Questions?

More Related