Search notes:

SAS: proc ds2

data work.tq84_ds;
  foo = 'The foo,';
  bar = 'the bar';
  baz = 'and the baz.';
  output;
  foo = 'one';
  bar = 'two';
  baz = 'three';
  output;
run;


proc ds2;
  data _null_;
    method init();
      dcl varchar(16) someMessage;
      someMessage = 'Starting...';
      put someMessage;
    end;
    method run();
      set work.tq84_ds;
      put foo bar baz;
    end;
    method term();
      put 'Finished!';
    end;
  enddata;
  run;
quit;
Github repository about-SAS, path: /programming/proc/ds2/basic.sas

Get data from an SQL statement

Get the data in a data step from an sql statement:
data work.numbers_english;
     length txt $10.;
     num = 1; txt = 'one'  ; output;
     num = 2; txt = 'two'  ; output;
     num = 3; txt = 'three'; output;
     num = 4; txt = 'four' ; output;
     num = 5; txt = 'five' ; output;
run;

data work.numbers_german;
     length txt $10.;
     num = 1; txt = 'eins' ; output;
     num = 2; txt = 'zwei' ; output;
     num = 3; txt = 'drei' ; output;
     num = 4; txt = 'vier' ; output;
     num = 5; txt = 'fünf' ; output;
run;


proc ds2;
  data translations_2_through_4;
    method run();
      set {
        select
           en.num as num,
           en.txt as num_english,
           gr.txt as num_german
        from
          work.numbers_english en join
          work.numbers_german  gr on en.num = gr.num
        where
          en.num between 2 and 4
      };
    end;
  enddata;
  run;
quit;

proc print data=work.translations_2_through_4; run;

/* Cleanup */
proc datasets library=work;
     delete
       translations_2_through_4
       numbers_english
       numbers_german;
run;
Github repository about-SAS, path: /programming/proc/ds2/embed-sql-statement.sas

See also

SAS programming: proc

Index