SAS PROGRAMMING HANDOUT #9 SOME COMPLEX INPUT STATEMENTS There are several different DO loops possible in the SAS data step. The @ symbol in this example is called a "trailing at-sign". It holds a data line for the next input statement in the step. This example is useful when one has a long list a data, and you only want to type in the Y-values and have SAS generate the A, and B values DATA TWO; DO A=1 TO 3; DO B=1 TO 2; INPUT Y @; OUTPUT; END; END; CARDS; 1 2 3 4 5 6 7 8 9 10 11 12 PROC PRINT; RUN; This example is very common, in the sense that you might receive data in this form. Again the @ symbol keeps the pointer when it was. Here the RETAIN statement keeps the value of the variables the same until a new value is assigned. Notice that depending on the value of TYPE different INPUTs are used. DATA THREE; INPUT TYPE $ @ ; IF TYPE='C' THEN INPUT COURSE $ PROF $; RETAIN COURSE PROF; ELSE IF TYPE='S' THEN INPUT NAME $ SCORE; CARDS; C MATHSTAT RALESCU S JIM 28 S BOB 47 S SARAH 100 C SASPROGRAMMING DEDDENS S JIM 98 S BOB 65 etc DATA TWO; SET ONE; IF TYPE='C' THEN DELETE; PROC PRINT DATA=TWO; RUN; This example is somewhat complicated and can be skipped. It illustrates RETAIN, and various DO's, IF-THEN's, and INPUT's in the data step DATA FOUR; RETAIN CITY SNAME; INFILE CARDS; INPUT @1 CITY $ @; DO SPORT=1 TO 4; INPUT SNAME $ N @; IF N=0 THEN DO; TEAMNAME='-----'; OUTPUT; END; DO J=1 TO N; INPUT TEAMNAME $ @; OUTPUT; END; END; CARDS; CINCY BASEBALL 1 REDS BBALL 0 HOCKEY 1 CLONES FOOTBALLB 1 BENGALSG CHICAGO BASEBALL 2 CUBS WHSOX BBALL 1 BULLS HOCKEY 1 BHAWKS FOOTBALL 1 BEARS ; PROC PRINT; RUN;