Search notes:

SAS statements: if

if then

data _null_;
  do i = 1 to 10;

     if i > 5 then put i=;

  end;
run;
Github repository about-SAS, path: /programming/statements/if/then.sas

if then else

data _null_;
  do i = 1 to 9;

     if i > 5 then put i " >  5"; /* Note the semicolon! */
              else put i " <= 5";

  end;
run;
Github repository about-SAS, path: /programming/statements/if/else.sas

if then do

data _null_;

  do i = 1 to 10;

     if i = 5 then do;
         put "------------";
         put "-- i is 5 --";
         put "------------";
     end;

  end;

run;
Github repository about-SAS, path: /programming/statements/if/then-do.sas
See also if … then do … end

Subsetting if

/*  A subsetting if is an "if" without corresponding "then". */

data tq84_one;

  infile datalines;

  length col_2 $10;
  input
    col_1
    col_2
  ;

datalines;
1 one
2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
9 nine
;


data tq84_two;
  set tq84_one;

  /*
     While the drop and keep statements control which variables
     make it into the output, the subsetting if determines which
     obserrvations go there.
  */
  if col_2 gt 's';
  
run;

proc print data=tq84_two;
run;
Github repository about-SAS, path: /programming/statements/if/subsetting/simple-example.sas

Missing semicolon

data _null_;
  a = 42;
  if a = 42
     then put 'a=42' /* Note the missing semicolon! */
     else put 'a != 42';
run;
/*
  NOTE: Variable else is uninitialized.
  NOTE: Variable put is uninitialized.
  a=42. . a != 42
  NOTE: DATA statement used (Total process time):
        real time           0.00 seconds
        cpu time            0.00 seconds
*/
Github repository about-SAS, path: /programming/statements/if/missing-semicolon.sas

See also

%if
SAS statements

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Companie...', 1759415520, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Companies-Products/SAS/programming/statements/if/index(151): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78