SlideShare a Scribd company logo
1 of 153
Get the Scoop on the Loop  How Best to Write a Loop in the DATA Step Arthur Li Department of Information Science City of Hope Comprehensive Cancer Center  Duarte, CA
INTRODUCTION ,[object Object],[object Object],[object Object],[object Object]
COMPILATION AND EXECUTION PHASES Compilation Phase Execution  phase If there is no syntax error ,[object Object],[object Object],[object Object],[object Object]
IMPLICIT LOOP Patient: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],M1240 4 F2340 3 F2390 2 M2390 1 ID
IMPLICIT LOOP ,[object Object],RANUNI  (SEED) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; Patient: PDV: COMPILATION: ,[object Object],[object Object],Automatic variables: _N_ = 1: 1 st  observation is being processed _N_ = 2: 2 nd  observation is being processed M1240 4 F2340 3 F2390 2 M2390 1 ID K GROUP D RANNUM K ID D _ERROR_ D _N_
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; Patient: PDV: COMPILATION: ,[object Object],[object Object],Automatic variables: _ERROR_ = 1: signals the data error of the currently-processed observation M1240 4 F2340 3 F2390 2 M2390 1 ID K GROUP D RANNUM K ID D _ERROR_ D _N_
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; Patient: PDV: Variable exists in the INPUT dataset ,[object Object],[object Object],COMPILATION: M1240 4 F2340 3 F2390 2 M2390 1 ID K GROUP D RANNUM K ID D _ERROR_ D _N_
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; Patient: PDV: Variables being created in the DATA step ,[object Object],COMPILATION: M1240 4 F2340 3 F2390 2 M2390 1 ID K GROUP D RANNUM K ID D _ERROR_ D _N_
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; Patient: PDV: COMPILATION: D = dropped K = kept M1240 4 F2340 3 F2390 2 M2390 1 ID K GROUP D RANNUM K ID D _ERROR_ D _N_
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; 1 st  iteration: ,[object Object],[object Object],[object Object],Patient: PDV: EXECUTION: M1240 4 F2340 3 F2390 2 M2390 1 ID . 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; 1 st  iteration: ,[object Object],Patient: PDV: EXECUTION: M1240 4 F2340 3 F2390 2 M2390 1 ID . M2390 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; 1 st  iteration: ,[object Object],Patient: PDV: EXECUTION: M1240 4 F2340 3 F2390 2 M2390 1 ID 0.36993 M2390 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; 1 st  iteration: ,[object Object],Patient: PDV: EXECUTION: M1240 4 F2340 3 F2390 2 M2390 1 ID P 0.36993 M2390 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; 1 st  iteration: ,[object Object],Patient: PDV: Trial1: EXECUTION: M1240 4 F2340 3 F2390 2 M2390 1 ID P 0.36993 M2390 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ M2390 ID P GROUP 1
REVIEW: OUTPUT Statement data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output; run ; Explicit OUTPUT ,[object Object],[object Object],[object Object]
REVIEW: OUTPUT Statement data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output; run ; Implicit OUTPUT ,[object Object],[object Object],[object Object]
REVIEW: OUTPUT Statement data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output; run ; ,[object Object],[object Object],[object Object],[object Object]
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; 2 nd  iteration: ,[object Object],[object Object],[object Object],Patient: PDV: Trial1: EXECUTION: M1240 4 F2340 3 F2390 2 M2390 1 ID . M2390 0 2 K GROUP D RANNUM K ID D _ERROR_ D _N_ M2390 ID P GROUP 1
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; 2 nd  iteration: ,[object Object],Patient: PDV: Trial1: Skip a few iterations…. EXECUTION: M1240 4 F2340 3 F2390 2 M2390 1 ID . M2390 0 2 K GROUP D RANNUM K ID D _ERROR_ D _N_ M2390 ID P GROUP 1
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; The end of 4 th  iteration: ,[object Object],[object Object],Patient: PDV: Trial1: EXECUTION: M1240 4 F2340 3 F2390 2 M2390 1 ID D 0.51880 M1240 0 4 K GROUP D RANNUM K ID D _ERROR_ D _N_ D M1240 4 D F2340 3 D F2390 2 M2390 ID P GROUP 1
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; 5 th  iteration: ,[object Object],[object Object],[object Object],Patient: PDV: Trial1: EXECUTION: M1240 4 F2340 3 F2390 2 M2390 1 ID . M1240 0 5 K GROUP D RANNUM K ID D _ERROR_ D _N_ D M1240 4 D F2340 3 D F2390 2 M2390 ID P GROUP 1
IMPLICIT LOOP data  trial1 (drop=rannum); set  patient; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; run ; 5 th  iteration: ,[object Object],[object Object],Patient: PDV: Trial1: End-of-file marker EXECUTION: M1240 4 F2340 3 F2390 2 M2390 1 ID . M1240 0 5 K GROUP D RANNUM K ID D _ERROR_ D _N_ D M1240 4 D F2340 3 D F2390 2 M2390 ID P GROUP 1
EXPLICIT LOOP ,[object Object],[object Object],[object Object]
EXPLICIT LOOP data  trial2(drop = rannum); id =  'M2390' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'F2390' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'F2340' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'M1240' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; run ; Assigning IDs in the DATA step
EXPLICIT LOOP data  trial2(drop = rannum); id =  'M2390' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'F2390' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'F2340' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'M1240' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; run ; 4 explicit OUTPUT statements
EXPLICIT LOOP data  trial2(drop = rannum); id =  'M2390' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'F2390' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'F2340' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'M1240' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; run ; 4 almost identical blocks ,[object Object],[object Object],[object Object]
ITERATIVE DO LOOP ,[object Object],DO  INDEX-VARIABLE = VALUE1, VALUE2, …, VALUEN ; SAS   STATEMENTS END; ,[object Object],[object Object],[object Object]
ITERATIVE DO LOOP data  trial2(drop = rannum); id =  'M2390' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'F2390' ; ... id =  'F2340' ;   ... id =  'M1240' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; run ; DO  INDEX-VARIABLE = VALUE1, VALUE2, …, VALUEN ; SAS   STATEMENTS END; ,[object Object],[object Object],[object Object],[object Object],rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ;
ITERATIVE DO LOOP data  trial2(drop = rannum); id =  'M2390' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; id =  'F2390' ; ... id =  'F2340' ;   ... id =  'M1240' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; run ; DO  INDEX-VARIABLE = VALUE1, VALUE2, …, VALUEN ; SAS  STATEMENTS END; data  trial2 (drop = rannum); do  id =  'M2390' ,  'F2390' ,  'F2340' ,  'M1240' ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ;
ITERATIVE DO LOOP DO  INDEX-VARIABLE = START  TO  STOP < BY  INCREMENT> ; SAS STATEMENTS END; ,[object Object],[object Object]
ITERATIVE DO LOOP DO  INDEX-VARIABLE = START  TO  STOP < BY  INCREMENT> ; SAS STATEMENTS END; ,[object Object],[object Object],[object Object]
ITERATIVE DO LOOP DO  INDEX-VARIABLE = START  TO  STOP < BY  INCREMENT> ; SAS STATEMENTS END; ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ITERATIVE DO LOOP DO  INDEX-VARIABLE = START  TO  STOP < BY  INCREMENT> ; SAS STATEMENTS END; ,[object Object],[object Object]
ITERATIVE DO LOOP data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],DO  INDEX-VARIABLE = START  TO  STOP < BY  INCREMENT> ; SAS STATEMENTS END; ,[object Object],[object Object],[object Object],[object Object]
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],[object Object],PDV: . . 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  Iteration of DO loop: . 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  Iteration of DO loop: 0.36993 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  Iteration of DO loop: P 0.36993 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  Iteration of DO loop: P 0.36993 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ 1 ID P GROUP 1
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  Iteration of DO loop: P 0.36993 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ 1 ID P GROUP 1
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 2 nd  Iteration of DO loop: P 0.36993 2 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ 1 ID P GROUP 1
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 2 nd  Iteration of DO loop: P 0.94018 2 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ 1 ID P GROUP 1
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 2 nd  Iteration of DO loop: D 0.94018 2 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ 1 ID P GROUP 1
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 2 nd  Iteration of DO loop: D 0.94018 2 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ D 2 2 1 ID P GROUP 1
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: D 0.94018 2 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ D 2 2 1 ID P GROUP 1
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 4 th  Iteration of DO loop: D 0.51880 4 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ D 4 4 D 3 3 D 2 2 1 ID P GROUP 1
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 5 th  iteration of DO loop: D 0.51880 5 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ D 4 4 D 3 3 D 2 2 1 ID P GROUP 1
ITERATIVE DO LOOP: EXECUTION PHASE data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],[object Object],PDV: D 0.51880 5 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ D 4 4 D 3 3 D 2 2 1 ID P GROUP 1
EXECUTING LOOPS CONDITIONALLY ,[object Object],[object Object],[object Object]
DO WHILE DO WHILE  (EXPRESSION) ; SAS STATEMENTS END; ,[object Object],[object Object]
DO WHILE DO WHILE  (EXPRESSION) ; SAS STATEMENTS END; data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; Iterative DO loop: DO WHILE loop:
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],[object Object],[object Object],PDV: At the beginning of the execution phase: . 0 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  iteration of the DO WHILE loop: . 0 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  iteration of the DO WHILE loop: . 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  iteration of the DO WHILE loop: 0.36993 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  iteration of the DO WHILE loop: P 0.36993 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  iteration of the DO WHILE loop: P 0.36993 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ 1 ID P GROUP 1
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 1 st  iteration of the DO WHILE loop: P 0.36993 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ 1 ID P GROUP 1
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 2 nd  iteration of the DO WHILE loop: P 0.36993 1 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ 1 ID P GROUP 1
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; ,[object Object],PDV: 2 nd  iteration of the DO WHILE loop: P 0.36993 2 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ 1 ID P GROUP 1
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; PDV: ,[object Object],P 0.36993 2 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ 1 ID P GROUP 1
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; PDV: At the end of the 4 th  iteration: ,[object Object],D 0.51880 4 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ D 4 4 D 3 3 D 2 2 1 ID P GROUP 1
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; PDV: 5 th  iteration: ,[object Object],D 0.51880 4 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ D 4 4 D 3 3 D 2 2 1 ID P GROUP 1
DO WHILE data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; PDV: 5 th  iteration: ,[object Object],D 0.51880 4 0 1 K GROUP D RANNUM K ID D _ERROR_ D _N_ D 4 4 D 3 3 D 2 2 1 ID P GROUP 1
DO UNTIL ,[object Object],[object Object],[object Object],DO UNTIL  (EXPRESSION) ; SAS STATEMENTS END;
DO UNTIL DO UNTIL  (EXPRESSION) ; SAS STATEMENTS END; data  trial3 (drop = rannum); do  id =  1   to   4 ; rannum = ranuni( 2 ); if  rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; data  trial4 (drop=rannum); do   while  (id <  4 ); id +  1 ; rannum = ranuni( 2 ); if   rannum>  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; Iterative DO loop: DO WHILE loop: data  trial5 (drop=rannum); do   until  (id >= 4 ); id + 1 ; rannum = ranuni( 2 ); if  rannum >  0.5   then  group = 'D' ; else  group = 'P' ; output ; end ; run ; DO UNTIL loop: Will not continue if the EXPRESSION is false Will not continue for another iteration if the EXPRESSION is true
NESTED LOOPS ,[object Object],[object Object],data  trial6; length  center $ 4 ; do  center =  &quot;COH&quot; ,  &quot;UCLA&quot; ,  &quot;USC&quot; ;  do  id =  1   to   4 ;  if  ranuni( 2 ) >  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; end ; run ; Outer loop Inner loop
NESTED LOOPS ,[object Object],[object Object],Obs  center  id  group 1  COH  1  P 2  COH  2  D 3  COH  3  D 4  COH  4  D 5  UCLA  1  D 6  UCLA  2  D 7  UCLA  3  P 8  UCLA  4  P 9  USC  1  P 10  USC  2  P 11  USC  3  D 12  USC  4  P
COMBINING IMPLICIT AND EXPLICIT LOOPS ,[object Object],[object Object],[object Object],data  trial7; set  cancer_center; do  id =  1   to   4 ; if   ranuni( 2 )>  0.5   then  group =  'D' ; else  group = 'P' ; output ; end ; run ; DATA step: implicit loop USC 3 UCLA 2 COH CENTER 1 explicit loop
UTILIZING LOOPS TO CREATE SAMPLES DIRECT ACCESS MODE ,[object Object],[object Object],[object Object],sequentially The end-of-file marker 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
DIRECT ACCESS MODE ,[object Object],09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 Direct Access
DIRECT ACCESS MODE ,[object Object],Step1:   Tell SAS which observation you would like to select  by using POINT = in the SET statement SET SAS-DATA-SET POINT = VARIABLE; ,[object Object],[object Object],09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
DIRECT ACCESS MODE ,[object Object],Step1:   Tell SAS which observation you would like to select  by using POINT = in the SET statement SET SAS-DATA-SET POINT = VARIABLE; ,[object Object],09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
DIRECT ACCESS MODE ,[object Object],Step1:   Tell SAS which observation you would like to select  by using POINT = in the SET statement SET SAS-DATA-SET POINT = VARIABLE; For example, to select the 5 th  observation… data  sample1; obs_n =  5 ; set  sbp point= obs_n; run ; Sbp: 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
DIRECT ACCESS MODE ,[object Object],[object Object],[object Object],data  sample1; obs_n =  5 ; set  sbp point= obs_n; run ; Sbp: The end-of-file marker 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
DIRECT ACCESS MODE ,[object Object],[object Object],[object Object],[object Object],STOP; data  sample1; obs_n =  5 ; set  sbp point= obs_n; stop ; run ; Sbp: 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
DIRECT ACCESS MODE ,[object Object],Step3:   Use the OUTPUT statement data  sample1; obs_n =  5 ; set  sbp point= obs_n; stop ; run ; Sbp: Implicit output Recall: If there is no explicit OUTPUT, SAS writes the observations to the output data at the end of the DATA step 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
DIRECT ACCESS MODE ,[object Object],Step3:   Use the OUTPUT statement data  sample1; obs_n =  5 ; set  sbp point= obs_n; stop ; run ; Sbp: Implicit output DATA step processing stop DATA step processing stops  BEFORE  the end of the DATA step   Implicit OUTPUT will not be reached! 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
DIRECT ACCESS MODE ,[object Object],Step3:   Use the OUTPUT statement data  sample1; obs_n =  5 ; set  sbp point= obs_n; output; stop ; run ; Sbp: Add the OUTPUT statement before the STOP 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
CREATING A SYSTEMATIC SAMPLE ,[object Object],[object Object],09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 07 04 01 ID 127 3 106 2 145 SBP 1
CREATING A SYSTEMATIC SAMPLE ,[object Object],[object Object],DO  INDEX-VARIABLE = START  TO  STOP < BY  INCREMENT> ; SAS STATEMENTS END; 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 1 total # of obs. k -  every  k th  obs.
CREATING A SYSTEMATIC SAMPLE ,[object Object],SET  SAS-DATA-SET  NOBS  = VARIABLE; ,[object Object],[object Object],[object Object],[object Object]
CREATING A SYSTEMATIC SAMPLE PDV: At the beginning of the execution phase: ,[object Object],[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; _ERROR_ is not shown for simplicity . 9 0 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: At the beginning of the execution phase: ,[object Object],[object Object],[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; . 9 0 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 1 st   iteration of the DO loop: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; . 9 1 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 1 st   iteration of the DO loop: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; 145 01 9 1 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 1 st   iteration of the DO loop: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 145 01 9 1 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 1 st   iteration of the DO loop: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 145 01 9 1 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 2 nd  iteration of the DO loop: ,[object Object],[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 145 01 9 4 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 2 nd  iteration of the DO loop: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 106 04 9 4 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 2 nd  iteration of the DO loop: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 106 04 9 4 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 106 04 2 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 2 nd  iteration of the DO loop: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 106 04 9 4 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 106 04 2 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 3 rd  iteration of the DO loop: ,[object Object],[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 106 04 9 7 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 106 04 2 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 3 rd  iteration of the DO loop: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 127 07 9 7 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 106 04 2 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 3 rd  iteration of the DO loop: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 127 07 9 7 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 127 07 3 106 04 2 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 3 rd  iteration of the DO loop: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 127 07 9 7 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 127 07 3 106 04 2 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: 4 th  iteration of the DO loop: ,[object Object],[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 127 07 9 10 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 127 07 3 106 04 2 01 ID 145 SBP 1
CREATING A SYSTEMATIC SAMPLE PDV: ,[object Object],data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Sample2: 127 07 9 10 1 K SBP K ID D TOTAL D CHOOSE D _N_ 09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1 127 07 3 106 04 2 01 ID 145 SBP 1
CREATING A RANDOM SAMPLE WITH REPLACEMENT ,[object Object],[object Object],[object Object],[object Object]
CREATING A RANDOM SAMPLE WITH REPLACEMENT data  sample2; do  choose =  1   to  total  by   3 ; set  sbp point = choose nobs = total; output ; end ; stop ; run ; Systematic sample ,[object Object],[object Object],09 08 07 06 05 04 03 02 01 ID 113 9 119 8 127 7 112 6 151 5 106 4 126 3 119 2 145 SBP 1
CREATING A RANDOM SAMPLE WITH REPLACEMENT data  sample3 (drop= i); do  i = 1   to   3 ; choose = ceil(ranuni( 5 )*total); set  sbp point=choose nobs=total; output ; end ; stop ; run ; ,[object Object],RANUNI(SEED) A randomly generated real number (0,1) N Total number of observations RANUNI(SEED)*N A real number (0, N) CEIL(RANUNI(SEED)*N) An integer [1, N]
CREATING A RANDOM SAMPLE WITHOUT REPLACEMENT SELF STUDY!
UTILIZING LOOPS TO READ A LIST OF EXTERNAL FILES THE INFILE STATEMENT WITH THE END= OPTION ,[object Object],[object Object],text1.txt: 01 145 02 119 data  example13; infile   &quot;C:ext1.txt&quot; ; input  id $ sbp; run ; ,[object Object],[object Object],[object Object],End-of-file  marker
THE INFILE STATEMENT WITH THE END= OPTION ,[object Object],Input dataset: Output dataset: PDV: M1240 4 F2340 3 F2390 2 M2390 1 ID D M1240 4 D F2340 3 D F2390 2 M2390 ID P GROUP 1 D 0.51880 M1240 0 4 K GROUP D RANNUM K ID D _ERROR_ D _N_
THE INFILE STATEMENT WITH THE END= OPTION ,[object Object],Input dataset: Output dataset: PDV: 01 145 02 119 Input buffer: Used to hold raw data 119 02 2 01 ID 145 SBP 1 119 02 0 2 K SBP K ID D _ERROR_ D _N_ … 9 1 1 2 0 … 6 5 4 3 2 1
THE INFILE STATEMENT WITH THE END= OPTION ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],INFILE  FILE-SPECIFICATION  END  = VARIABLE; The VARIABLE is set to 1 when SAS reads the last record of the external file;  otherwise it sets to 0
THE INFILE STATEMENT WITH THE END= OPTION ,[object Object],data  example14; infile   &quot;C:ext1.txt&quot;   end  = last; do   until  (last =  1 ); input  id $ sbp; output ; end ; run ; ,[object Object],[object Object]
THE INFILE STATEMENT WITH THE FILEVAR = OPTION ,[object Object],[object Object],infile   &quot;C:ext1.txt&quot; ; INFILE  FILE-SPECIFICATION  FILEVAR  = VARIABLE ,[object Object],[object Object],A placeholder, not an actual filename
THE INFILE STATEMENT WITH THE FILEVAR = OPTION ,[object Object],data  example15; filename =  &quot;C:ext1.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; run ; 167  data example14; 168  filename = &quot;C:ext1.txt&quot;; 169  infile dummy filevar =   filename; 170  input id $ sbp; 171  run; NOTE: The infile DUMMY is: File Name=C:ext1.txt, RECFM=V,LRECL=256 NOTE: 2 records were read from the infile DUMMY. The minimum record length was 6. The maximum record length was 6. NOTE: The data set WORK.EXAMPLE13 has 2 observations and 2 variables.
READING MULTIPLE EXTERNAL FILES text1.txt: 01 145 02 119 text2.txt: 03 126 04 106  text3.txt: 05 140 06 118  read concatenate   Identical Format: ,[object Object],06 05 04 03 02 01 ID 118 6 140 5 106 4 126 3 119 2 145 SBP 1
READING MULTIPLE EXTERNAL FILES text1.txt: 01 145 02 119 text2.txt: 03 126 04 106  text3.txt: 05 140 06 118  read concatenate   Identical Format: ,[object Object],06 05 04 03 02 01 ID 118 6 140 5 106 4 126 3 119 2 145 SBP 1
READING MULTIPLE EXTERNAL FILES text1.txt: 01 145 02 119 data  example15 ; filename =  &quot;C:ext1.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; run ; text2.txt: 03 126 04 106  text3.txt: 05 140 06 118  ,[object Object]
READING MULTIPLE EXTERNAL FILES text1.txt: 01 145 02 119 data  example15 ; filename =  &quot;C:ext1.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; run ; text2.txt: 03 126 04 106  text3.txt: 05 140 06 118  ,[object Object],do  i =  1   to   3 ; end ;
READING MULTIPLE EXTERNAL FILES text1.txt: 01 145 02 119 data  example15 ; filename =  &quot;C:ext1.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; run ; text2.txt: 03 126 04 106  text3.txt: 05 140 06 118  ,[object Object],do  i =  1   to   3 ; end ;
READING MULTIPLE EXTERNAL FILES text1.txt: 01 145 02 119 data  example15 ; filename =  &quot;C:ext1.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; run ; text2.txt: 03 126 04 106  text3.txt: 05 140 06 118  do  i =  1   to   3 ; end ; filename =  &quot;C:ext&quot;  ||  put(i,  1. ) ||  &quot;.txt&quot; ; filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ;
READING MULTIPLE EXTERNAL FILES text1.txt: 01 145 02 119 data  example15 ; filename =  &quot;C:ext1.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; run ; text2.txt: 03 126 04 106  text3.txt: 05 140 06 118  do  i =  1   to   3 ; end ; filename =  &quot;C:ext&quot;  ||  put(i,  1. ) ||  &quot;.txt&quot; ; ,[object Object],output ;
READING MULTIPLE EXTERNAL FILES text1.txt: 01 145 02 119 data  example15 ; filename =  &quot;C:ext1.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; run ; text2.txt: 03 126 04 106  text3.txt: 05 140 06 118  do  i =  1   to   3 ; end ; filename =  &quot;C:ext&quot;  ||  put(i,  1. ) ||  &quot;.txt&quot; ; ,[object Object],[object Object],output ; stop ;
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],[object Object],At the beginning of the DATA step: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 K ID . . 1 K SBP D FILENAME D I D _N_
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],1 st  iteration of the DO loop: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 K ID . 1 1 K SBP D FILENAME D I D _N_
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],1 st  iteration of the DO loop: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 K ID . C:ext1.txt 1 1 K SBP D FILENAME D I D _N_
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],[object Object],1 st  iteration of the DO loop: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 Input buffer: K ID D 0 LAST . C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 5 4 1 1 0 … 6 5 4 3 2 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],1 st  iteration of the DO loop: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 Input buffer: K 01 ID 145 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 5 4 1 1 0 … 6 5 4 3 2 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],1 st  iteration of the DO loop: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 K 01 ID 145 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],1 st  iteration of the DO loop: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 K 01 ID 145 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],2 nd  iteration of the DO loop: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 K 01 ID 145 C:ext1.txt 2 1 K SBP D FILENAME D I D _N_ 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],2 nd  iteration of the DO loop: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 K 01 ID 145 C:ext2.txt 2 1 K SBP D FILENAME D I D _N_ 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],[object Object],2 nd  iteration of the DO loop: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 Input buffer: ??? K 01 ID 145 C:ext2.txt 2 1 K SBP D FILENAME D I D _N_ … 6 2 1 3 0 … 6 5 4 3 2 1 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; ,[object Object],2 nd  iteration of the DO loop: text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 Input buffer: ??? K 01 ID 145 C:ext2.txt 2 1 K SBP D FILENAME D I D _N_ … 6 2 1 3 0 … 6 5 4 3 2 1 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; ,[object Object],[object Object],[object Object],At the beginning of the DATA step: K ID D 0 LAST . . 1 K SBP D FILENAME D I D _N_
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; ,[object Object],1 st  Iteration of the DO loop (outer loop): K ID D 0 LAST . 1 1 K SBP D FILENAME D I D _N_
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): ,[object Object],K ID D 0 LAST . C:ext1.txt 1 1 K SBP D FILENAME D I D _N_
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): ,[object Object],1 st  Iteration of the DO UNTIL loop (inner loop): K ID D 0 LAST . C:ext1.txt 1 1 K SBP D FILENAME D I D _N_
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): ,[object Object],[object Object],1 st  Iteration of the DO UNTIL loop (inner loop): Input buffer: K ID D 0 LAST . C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 5 4 1 1 0 … 6 5 4 3 2 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): ,[object Object],[object Object],1 st  Iteration of the DO UNTIL loop (inner loop): Input buffer: K 01 ID D 0 LAST 145 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 5 4 1 1 0 … 6 5 4 3 2 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): 1 st  Iteration of the DO UNTIL loop (inner loop): Input buffer: ,[object Object],[object Object],K 01 ID D 0 LAST 145 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 5 4 1 1 0 … 6 5 4 3 2 1 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): 1 st  Iteration of the DO UNTIL loop (inner loop): Input buffer: ,[object Object],[object Object],K 01 ID D 0 LAST 145 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 5 4 1 1 0 … 6 5 4 3 2 1 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): 2 nd  Iteration of the DO UNTIL loop (inner loop): Input buffer: ,[object Object],K 01 ID D 0 LAST 145 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 5 4 1 1 0 … 6 5 4 3 2 1 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): 2 nd  Iteration of the DO UNTIL loop (inner loop): Input buffer: ,[object Object],[object Object],K 01 ID D 1 LAST 145 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 9 1 1 2 0 … 6 5 4 3 2 1 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): 2 nd  Iteration of the DO UNTIL loop (inner loop): Input buffer: ,[object Object],K 02 ID D 1 LAST 119 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 9 1 1 2 0 … 6 5 4 3 2 1 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): 2 nd  Iteration of the DO UNTIL loop (inner loop): Input buffer: ,[object Object],[object Object],K 02 ID D 1 LAST 119 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 9 1 1 2 0 … 6 5 4 3 2 1 119 02 2 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): 2 nd  Iteration of the DO UNTIL loop (inner loop): Input buffer: ,[object Object],[object Object],K 02 ID D 1 LAST 119 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ … 9 1 1 2 0 … 6 5 4 3 2 1 119 02 2 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 1 st  Iteration of the DO loop (outer loop): ,[object Object],K 02 ID D 1 LAST 119 C:ext1.txt 1 1 K SBP D FILENAME D I D _N_ 119 02 2 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 2 nd  Iteration of the DO loop (outer loop): ,[object Object],[object Object],K 02 ID D 1 LAST 119 C:ext1.txt 2 1 K SBP D FILENAME D I D _N_ 119 02 2 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 2 nd  Iteration of the DO loop (outer loop): ,[object Object],K 02 ID D 1 LAST 119 C:ext2.txt 2 1 K SBP D FILENAME D I D _N_ 119 02 2 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 2 nd  Iteration of the DO loop (outer loop): ,[object Object],1 st  Iteration of the DO UNTIL loop (inner loop): K 02 ID D 1 LAST 119 C:ext2.txt 2 1 K SBP D FILENAME D I D _N_ 119 02 2 01 ID 145 SBP 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 2 nd  Iteration of the DO loop (outer loop): ,[object Object],[object Object],1 st  Iteration of the DO UNTIL loop (inner loop): Input buffer: K 02 ID D 0 LAST 119 C:ext2.txt 2 1 K SBP D FILENAME D I D _N_ 119 02 2 01 ID 145 SBP 1 … 6 2 1 3 0 … 6 5 4 3 2 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 2 nd  Iteration of the DO loop (outer loop): ,[object Object],[object Object],1 st  Iteration of the DO UNTIL loop (inner loop): Input buffer: K 03 ID D 0 LAST 126 C:ext2.txt 2 1 K SBP D FILENAME D I D _N_ 119 02 2 01 ID 145 SBP 1 … 6 2 1 3 0 … 6 5 4 3 2 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 2 nd  Iteration of the DO loop (outer loop): ,[object Object],[object Object],1 st  Iteration of the DO UNTIL loop (inner loop): Input buffer: K 03 ID D 0 LAST 126 C:ext2.txt 2 1 K SBP D FILENAME D I D _N_ 126 03 3 119 02 2 01 ID 145 SBP 1 … 6 2 1 3 0 … 6 5 4 3 2 1
READING MULTIPLE EXTERNAL FILES data  example15 (drop = i); do  i =  1   to   3 ;    filename =  &quot;C:ext&quot;  || put(i,  1. ) ||  &quot;.txt&quot; ; infile  dummy  filevar  = filename; input  id $ sbp; output ; end; stop; run ; text1.txt: 01 145  02 119 text2.txt: 03 126  04 106 text3.txt: 05 140  06 118 do   until  (last);   infile  dummy  filevar  = filename  end =last; input  id $ sbp; output ; end ; 2 nd  Iteration of the DO loop (outer loop): ,[object Object],1 st  Iteration of the DO UNTIL loop (inner loop): Input buffer: K 03 ID D 0 LAST 126 C:ext2.txt 2 1 K SBP D FILENAME D I D _N_ 126 03 3 119 02 2 01 ID 145 SBP 1 … 6 2 1 3 0 … 6 5 4 3 2 1
ARRAY ,[object Object],[object Object]
CONCLUSION ,[object Object],[object Object],[object Object]
CONTACT INFORMATION ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

Similar to Get the scoop on the loop how best to write a loop in the data step

Conditional statements
Conditional statementsConditional statements
Conditional statementsNabishaAK
 
Data Match Merging in SAS
Data Match Merging in SASData Match Merging in SAS
Data Match Merging in SASguest2160992
 
E1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxE1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxjacksnathalie
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docxshandicollingwood
 
Chapter 3 branching v4
Chapter 3 branching v4Chapter 3 branching v4
Chapter 3 branching v4Sunarto Quek
 
Here is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docxHere is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docxtrappiteboni
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa Thapa
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptxeaglesniper008
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdfRanjeetaSharma8
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Abou Bakr Ashraf
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programmingPriyansh Thakar
 
Programming in Oracle with PL/SQL
Programming in Oracle with PL/SQLProgramming in Oracle with PL/SQL
Programming in Oracle with PL/SQLlubna19
 

Similar to Get the scoop on the loop how best to write a loop in the data step (19)

Python for Beginners(v2)
Python for Beginners(v2)Python for Beginners(v2)
Python for Beginners(v2)
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
Decision Making and Branching
Decision Making and BranchingDecision Making and Branching
Decision Making and Branching
 
BLM101_2.pptx
BLM101_2.pptxBLM101_2.pptx
BLM101_2.pptx
 
Issta13 workshop on debugging
Issta13 workshop on debuggingIssta13 workshop on debugging
Issta13 workshop on debugging
 
Data Match Merging in SAS
Data Match Merging in SASData Match Merging in SAS
Data Match Merging in SAS
 
E1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxE1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docx
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
 
Chapter 3 branching v4
Chapter 3 branching v4Chapter 3 branching v4
Chapter 3 branching v4
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
PLSQLIV.ppt
PLSQLIV.pptPLSQLIV.ppt
PLSQLIV.ppt
 
Here is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docxHere is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docx
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdf
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
Programming in Oracle with PL/SQL
Programming in Oracle with PL/SQLProgramming in Oracle with PL/SQL
Programming in Oracle with PL/SQL
 

Recently uploaded

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Get the scoop on the loop how best to write a loop in the data step

  • 1. Get the Scoop on the Loop How Best to Write a Loop in the DATA Step Arthur Li Department of Information Science City of Hope Comprehensive Cancer Center Duarte, CA
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. IMPLICIT LOOP data trial1 (drop=rannum); set patient; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; run ; Patient: PDV: COMPILATION: D = dropped K = kept M1240 4 F2340 3 F2390 2 M2390 1 ID K GROUP D RANNUM K ID D _ERROR_ D _N_
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. EXPLICIT LOOP data trial2(drop = rannum); id = 'M2390' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; id = 'F2390' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; id = 'F2340' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; id = 'M1240' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; run ; Assigning IDs in the DATA step
  • 26. EXPLICIT LOOP data trial2(drop = rannum); id = 'M2390' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; id = 'F2390' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; id = 'F2340' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; id = 'M1240' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; run ; 4 explicit OUTPUT statements
  • 27.
  • 28.
  • 29.
  • 30. ITERATIVE DO LOOP data trial2(drop = rannum); id = 'M2390' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; id = 'F2390' ; ... id = 'F2340' ; ... id = 'M1240' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; run ; DO INDEX-VARIABLE = VALUE1, VALUE2, …, VALUEN ; SAS STATEMENTS END; data trial2 (drop = rannum); do id = 'M2390' , 'F2390' , 'F2340' , 'M1240' ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; end ; run ;
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52. DO WHILE DO WHILE (EXPRESSION) ; SAS STATEMENTS END; data trial3 (drop = rannum); do id = 1 to 4 ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; end ; run ; data trial4 (drop=rannum); do while (id < 4 ); id + 1 ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; end ; run ; Iterative DO loop: DO WHILE loop:
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67. DO UNTIL DO UNTIL (EXPRESSION) ; SAS STATEMENTS END; data trial3 (drop = rannum); do id = 1 to 4 ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; end ; run ; data trial4 (drop=rannum); do while (id < 4 ); id + 1 ; rannum = ranuni( 2 ); if rannum> 0.5 then group = 'D' ; else group = 'P' ; output ; end ; run ; Iterative DO loop: DO WHILE loop: data trial5 (drop=rannum); do until (id >= 4 ); id + 1 ; rannum = ranuni( 2 ); if rannum > 0.5 then group = 'D' ; else group = 'P' ; output ; end ; run ; DO UNTIL loop: Will not continue if the EXPRESSION is false Will not continue for another iteration if the EXPRESSION is true
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103. CREATING A RANDOM SAMPLE WITHOUT REPLACEMENT SELF STUDY!
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116. READING MULTIPLE EXTERNAL FILES text1.txt: 01 145 02 119 data example15 ; filename = &quot;C:ext1.txt&quot; ; infile dummy filevar = filename; input id $ sbp; run ; text2.txt: 03 126 04 106 text3.txt: 05 140 06 118 do i = 1 to 3 ; end ; filename = &quot;C:ext&quot; || put(i, 1. ) || &quot;.txt&quot; ; filename = &quot;C:ext&quot; || put(i, 1. ) || &quot;.txt&quot; ;
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.