/*
TIP SIX: CONDITIONALLY DEFINE NESTED SAS MACROS
*/
/*Conditional Nested SAS Macro Example*/
%macro stats1(product,year);
title "Statistics for &product in &year";
%if &year>1929 and &year<1935 %then
%do;
title2 "Some Data Might Be Missing";
%end;
%if &year >= 2001 %then
%do;
%macro analysis(type=);
proc means data=work.products;
where product="&product" and year=&year and type=&type;
run;
proc freq data=work.products;
tables year*type*product/list;
run;
%mend analysis;
%end;
%else
%do;
%macro analysis(type=);
proc means data=work.products;
where product="&product" and year=&year and type=&type;
run;
%mend analysis;
%end;
%do counter = 30 %to 50;
%analysis(&counter);
%end;
title;
%mend stats1;
%stats1(steel,2002)
%stats1(beef,2000)
%stats1(fiberglass,2001)
/*
conditional nested macro
*/
%macro divCardByGapSec(gapSec);
libname sdata "E:\ChenyxFiles\2014.Study.TrainingCertificate\SAS.Victoria\SAS.DS2\SASUniversityEdition\myfolders\sData";
%macro sqlRec(start,end);
proc sql;
select * from sData.cbillall where monotonic() between &start and &end;
quit;
%mend sqlRec;
%if &gapSec < 300 %then
%sqlRec(1,2);
%else %if &gapSec > 300 %then
%sqlRec(10,20);
%else
%sqlRec(10,200);
%mend divCardByGapSec;
%divCardByGapSec(200);
%divCardByGapSec(600);
No comments:
Post a Comment