Вы находитесь на странице: 1из 11

%MACRO select(customer=,sortvar=); proc sort data=flowersales; BY quantity variety; WHERE CustomerID = "&customer"; PROC PRINT DATA = flowersales; FORMAT

SaleDate WORDDATE18.; TITLE1 "Orders for Customer Number &customer"; TITLE2 "Sorted by &sortvar"; %MEND select; %select(customer = 356W, sortvar = Quantity) %select(customer = 240W, sortvar = Variety) RUN; %LET flowertype = Ginger; DATA flowersales; INFILE datalines; INPUT CustomerID $ SaleDate MMDDYY10. Variety $9. @26Quantity; IF Variety = "&flowertype" ; datalines; 240W 02-07-2003 Ginger 120 240W 02-07-2003 Protea 180 356W 02-08-2003 Heliconia 60 356W 02-08-2003 Anthurium 300 188R 02-11-2003 Ginger 24 188R 02-11-2003 Anthurium 24 240W 02-12-2003 Heliconia 48 240W 02-12-2003 Protea 48 356W 02-12-2003 Ginger 240 ;run; PROC PRINT DATA = flowersales; FORMAT SaleDate WORDDATE18.; TITLE "Sales of &flowertype"; RUN; LIBNAME MACROLIB '\\TSCLIENT\C\SAS_CODE\CODE'; OPTIONS MSTORED SASMSTORE=MACROLIB;

%MACRO ODBC/STORE; PROC SQL; CONNECT TO ODBC AS ADMINISTRATOR (DATASRC=&DSN USER=neeraj PASSWORD='neeraj'); CREATE VIEW &LIB&LIB_TABLE AS SELECT * FROM CONNECTION TO ADMINISTRATOR( SELECT * FROM &ODBC_TABLE); QUIT; %MEND ODBC;

%MACRO SEMMA/STORE; PROC SQL STIMER; CREATE TABLE TEMP AS SELECT * FROM &LIB.&LIB_TABLE; SELECT COUNT(*) INTO :N FROM TEMP; CREATE TABLE &LIB.POPULATION AS SELECT * FROM TEMP; UPDATE &LIB.POPULATION SET &LEVELVAR='OTHER' WHERE &LEVELVAR IN (SELECT DISTINCT(&LEVELVAR) FROM (SELECT &LEVELVAR,COUNT(*) AS A FROM TEMP GROUP BY 1 HAVING (A /&N) <0.005 )); UPDATE &LIB.POPULATION SET SONG_CHARGE='FREE' WHERE SONG_CHARGE IS NULL; CREATE TABLE CH AS SELECT * FROM &LIB.POPULATION WHERE CHURN='1' ORDER BY &LEVELVAR; CREATE TABLE AC AS SELECT * FROM &LIB.POPULATION WHERE CHURN='0' ORDER BY &LEVELVAR; CREATE TABLE L1 AS SELECT DISTINCT(&LEVELVAR),INT(COUNT(*)/&PROPORTION) AS A FROM CH GROUP BY 1; SELECT A INTO : NM SEPARATED BY ' ' FROM L1; %PUT &NM; QUIT; PROC SURVEYSELECT DATA=CH OUT=MODEL_CH METHOD=SRS N=(&NM);

STRATA &LEVELVAR; RUN; PROC SURVEYSELECT DATA=AC OUT=MODEL_AC METHOD=SRS N=(&NM); STRATA &LEVELVAR; RUN; %MEND ; %MACRO KERNAL(INDATA=)/STORE; GOPTIONS RESET=GLOBAL GUNIT=PCT CBACK=BLACK COLORS=(YELLOW) CTEXT=WHITE FTITLE=SWISSB FTEXT=SWISS HTITLE=6 HTEXT=3; SYMBOL1 ; PROC UNIVARIATE DATA=&INDATA; HISTOGRAM / KERNEL(C = 0.25 0.50 0.75 1.00 L = 1 20 2 34 COLOR=YELLOW NOPRINT) CFILL = RED CFRAME = BLUE; QQPLOT; RUN; %MEND KERNAL; %MACRO TRANSFORM/STORE; DATA TRAIN VALID TEST; DROP SELECTIONPROB SAMPLINGWEIGHT; SET MODEL_CH MODEL_AC ; LOGNSS=LOG(NUM_SONG_SELECTION+1); LOGDCS=LOG(DIFF_CURR_SELECTION+1); LOGNVA=LOG(NUM_VOICE_ACCESS+1) ; LOGNSC=LOG(NUM_SONG_CAT+1) ; LOGANS=LOG(AVG_NEXT_SELECTION+1); LOGAGE=LOG(AGE); DROP NUM_SONG_SELECTION DIFF_CURR_SELECTION NUM_VOICE_ACCESS NUM_SONG_CAT AVG_NEXT_SELECTION AGE;

IF RANUNI(0)<=0.10 THEN OUTPUT TEST; ELSE IF 0.10<RANUNI(0)<=0.40 THEN OUTPUT VALID; ELSE OUTPUT TRAIN; RUN; %MEND TRANSFORM; %MACRO LOGIT(INDATA=,OUTMODEL=,ROC=,OUTPUT=, TEST=, SCORE=, PDF=)/STORE; DATA &LIB.COVAR; SET &INDATA (DROP= SUBSCRIBER_ID CHURN ); RUN; %LET DSID = %SYSFUNC(OPEN(&LIB.COVAR,I)); %LET VAR=; %DO I=1 %TO %SYSFUNC(ATTRN (&DSID,NVARS)); %LET VAR= &VAR %SYSFUNC(VARNAME(&DSID,&I)); %END; %PUT VAR=&VAR; %LET RC = %SYSFUNC(CLOSE(&DSID)); ODS GRAPHICS ON; ODS PDF FILE= "\\TSCLIENT\E\PREDICTION\&OPERATOR\&CIRCLE\&DATE&PDF REPORT.PDF"; PROC LOGISTIC DATA=&INDATA SIMPLE OUTMODEL=&OUTMODEL; CLASS &CLASSVAR; MODEL CHURN(EVENT='1') = &VAR / SELECTION=S

SLE=0.05 SLS=0.05 TECHNIQUE=NEWTON LACKFIT EXPB IPLOTS OUTROC=&ROC RSQ CLODDS=WALD SCALE=NONE NODUMMYPRINT NOLOGSCALE NOCHECK AGGREGATE ; OUTPUT OUT=&OUTPUT(KEEP= SUBSCRIBER_ID PROB HAT RESCHI RESDEV) P=PROB H=HAT RESCHI=RESCHI RESDEV=RESDEV PREDPROBS=CROSSVALIDATE; SCORE DATA =&TEST OUT=&SCORE(KEEP=SUBSCRIBER_ID P_1); RUN; PROC SQL; SELECT COUNT (*) FROM &SCORE WHERE P_1>=0.5; QUIT; PROC GPLOT DATA=&OUTPUT; PLOT RESDEV*PROB; PLOT RESCHI*PROB; LINK= LOGIT

PLOT HAT*PROB; RUN; QUIT; PROC UNIVARIATE DATA=&OUTPUT; VAR RESDEV RESCHI; HISTOGRAM RESDEV RESCHI /NORMAL(COLOR=RED W=3 PERCENT=20 40 60 80 MIDPERCENTS)CFILL= BLUE CFRAME = YELLOW; QQPLOT; RUN; QUIT; ODS GRAPHICS OFF; ODS PDF CLOSE; %MEND LOGIT;

%MACRO INFORMATION(OPERATOR=,CIRCLE=,DATE=,USER=,LAVELVAR=, PROPORTION=,LIB=, CATVAR=)/STORE; TITLE1 ONMOBILE GLOBAL BANGALORE (RPS); TITLE2 DEPARTMENT: BUSINESS INTELLIGENCE; TITLE3 OPERATOR: &OPERATOR; TITLE4 CIRCLE: &CIRCLE; FOOTNOTE STATISTICIAN : &USER; %LET OPERATOR=&OPERATOR; %LET CIRCLE=&CIRCLE; %LET DATE=&DATE; %LET CLASSVAR=&CATVAR ; %LET LEVELVAR=&LEVELVAR; %LET PROPORTION=&PROPORTION; %LET DSN=RBT_MODEL&OPERATOR&CIRCLE; %LET ODBC_TABLE=ANALYSIS_MODEL&DATE; %LET LIB=&LIB.;

%LET OC=&OPERATOR&CIRCLE&DATE; %LET LIB_TABLE=&OPERATOR&CIRCLE&DATE; %MEND INFORMATION; %MACRO SCORE(INMODEL=,SCORE=)/STORE; PROC SQL; CONNECT TO ODBC AS ADMINISTRATOR (DATASRC=&DSN USER=neeraj PASSWORD='neeraj'); CREATE TABLE TARGETED_BASE AS SELECT SUBSCRIBER_ID, EX_RBT, ACTIVATION_MODE, LAST_DEACT_MODE, RATE, PREPAID_STATUS, SONG_CHARGE, BEST_SELECTION_MODE, LOG(NUM_SONG_SELECTION+1) AS LOGNSS, LOG(DIFF_CURR_SELECTION+1)AS LOGDCS, LOG(NUM_VOICE_ACCESS+1) AS LOGNVA, LOG(NUM_SONG_CAT+1) AS LOGNSC, LOG(AVG_NEXT_SELECTION+1) AS LOGANS, LOG(AGE) AS LOGAGE FROM CONNECTION TO ADMINISTRATOR( SELECT * FROM &ODBC_TABLE WHERE CHURN='0'); QUIT; PROC LOGISTIC INMODEL=&INMODEL; SCORE DATA =TARGETED_BASE OUT=&SCORE(KEEP=SUBSCRIBER_ID P_1); RUN; PROC SQL; CREATE TABLE &LIB.PRE&OPERATOR&CIRCLE&DATE AS SELECT SUBSCRIBER_ID FROM &SCORE(KEEP= SUBSCRIBER_ID P_1) WHERE P_1 GE 0.50 ; QUIT; %MEND SCORE;

%MACRO EXPORT(PROMO)/STORE; PROC EXPORT DATA=&LIB.PRE&OPERATOR&CIRCLE&DATE OUTFILE="\\TSCLIENT\E\PREDICTION\&OPERATOR\&CIRCLE\& DATE&PROMO PROMO.CSV" DBMS=CSV REPLACE; RUN; %MEND; OPTIONS MSTORED SASMSTORE=MACROLIB; OPTIONS MLOGIC; OPTIONS MPRINT; OPTIONS SYMBOLGEN; OPTIONS MSGLEVEL=I; TITLE1 ONMOBILE GLOBAL BANGALORE (RPS); TITLE2 DEPARTMENT: BUSINESS INTELLIGENCE; TITLE3 OPERATOR: VODAFONE; TITLE4 CIRCLE: GUJARAT; FOOTNOTE STATISTICIAN : NEERAJ VERMA; %LET OPERATOR=_VODA; %LET CIRCLE=_GUJ; %LET DATE=_09SEP; %LET CLASSVAR=EX_RBT(REF='Yes') ACTIVATION_MODE(REF='Backend') LAST_DEACT_MODE(REF='Not Deactivated') RATE(REF='Default') PREPAID_STATUS(REF='Yes') SONG_CHARGE(REF='Default') BEST_SELECTION_MODE (REF='COPY'); %LET LEVELVAR=BEST_SELECTION_MODE; %LET PROPORTION=10; %LET DSN=RBT_MODEL&OPERATOR&CIRCLE; %LET ODBC_TABLE=ANALYSIS_MODEL&DATE; %LET LIB=RBT.;

%LET OC=&OPERATOR&CIRCLE&DATE; %LET LIB_TABLE=&OPERATOR&CIRCLE&DATE; %ODBC %SEMMA %TRANSFORM %LOGIT(INDATA=TRAIN,OUTMODEL=TRAIN_OUTMODEL,ROC=TRAI N_ROC,OUTPUT=TRAIN_OUTPUT, TEST=TEST, SCORE=TRAIN_SCORE, PDF=TRAIN) %LOGIT(INDATA=VALID,OUTMODEL=VALID_OUTMODEL,ROC=VALI D_ROC,OUTPUT=VALID_OUTPUT,TEST=TEST, SCORE=VALID_SCORE, PDF=VALID) /*Macro */ %macro seema; proc print data=seema.emp1; run; proc means data=seema.emp1; proc freq daTa=seema.emp1; table sal; run; %mend seema; %seema %put _all_; %let doll=sas data set; %put &doll;

/*%MACRO Statement with Positional Parameters*/ data samp; input ename $ eno esal; cards; hari 101 10000 ravi 103 20000

venu 105 30000 venkat 109 40000 ; run; %macro temp(dname,list,list2); proc print data=&dname; var &list &list2; run; %mend; %temp(samp,ename,esal);

/*%MACRO Statement with Keyword Parameters*/ %macro nn(dname=,dlist=); proc print data=&dname; var &dlist; run; %mend; %nn(dlist=eno,dname=samp);

%let dsn=new zealand; %put &dsn; data class; input c_id variety $ quantity; cards; 1001 ginger 120

1002 mango 120 1003 ginger 190 1002 ginger 288 ; run; %let dsn=ginger; (global macro variable) data seema; set class; if variety="&dsn"; proc print data=seema; title "sales of &dsn"; run;