SAS PROGRAMMING HANDOUT #20 This handout tries to illustrate various MACRO functions: %LET = assign a value to a macro variable %EVAL = evaluates arithmetic and logiscal expressions %SYMPUT = assigns a SAS variable value to a macro variable %SYMGET = assigns a macro variable value to a SAS variable %SCAN = scans for words in macro variable values %STR = used to surround character strings LIBNAME JIM 'A:\'; OPTIONS MACROGEN MPRINT MLOGIC SYMBOLGEN; DATA _NULL_; %LET Y=GNP; %LET A=RE; %LET B=G; %LET C=D; %LET E=F; %LET CF=INVEST; DATA &Y.1; SET JIM.GNP; PROC &A.&B; MODEL &Y=&&C&E; TITLE1 '1 &Y IS DEPENDENT VARIABLE'; TITLE2 "2 &Y IS DEPENDENT VARIABLE"; RUN; OPTIONS MACROGEN; %MACRO JIM; %LET X=2; *creates a macro variable &X whose value is 2; %LET Y = %EVAL(&X+1); *creates a macro variable &Y whose value is 3; DATA BOB; BB='BOB'; SS='SET'; NN=TRIM(LEFT(4)); *this left justifies and then trims the blanks; CALL SYMPUT('NEW',NN); *creates a macro variable &NEW whose value is 4; CALL SYMPUT('OLD',SS); *creates a macro variable &OLD whose value is SET; CALL SYMPUT('NEWEST',SYMGET('OLD') || " " || BB); *creates a macro variable &NEWEST whose value is SET BOB; PROC PRINT; RUN; DATA DD&NEW; *NOTE try this without trimming and left justifying; &NEWEST; F=1; RUN; %LET C=AB.CDE.FGHI.JKLMN; %LET D=%SCAN(&C,3,'.'); *creates a macro variable &D equal to the third "word"; *delimited by commas, that is FGHI; DATA D&D; %LET E=AB CDE FGHI JKLMN; %LET F=%SCAN(&E,2,%STR( )); *creates a macro variable &F equal to the second "word"; *delimited by spaces, that is CDE; %LET G=PROC SORT %STR(;) ; /*creates a macro variable &G equal to PROC SORT; */; %LET H=%STR(BY NN;) ; /*creates a macro variable &H equal to BY NN; */; DATA E&F; &NEWEST; &G &H *notice there are no semi-colons after &G and &H; %MEND; %JIM; RUN;