Wednesday, September 6, 2017

Sample codes for SAS View

SAS has two kinds of views: SQL view and DATA view. They work similarly but we need to know what's the difference. Here, I give out some samples for clarification.
/* create DATA view */
data a / view=a;
    set sashelp.class;
run;

/* Create SQL view */
proc sql;
    create view b as
        select * from sasehlp.class;
quit;

/* Display Data view definition. 
Note: it can't be used for SQL view. */
data view=a;
    describe;
run;

/* Display SQL view definition. 
Note: it can't be used for DATA view. */
proc sql;
    describe view b;
quit;

/* There are 4 ways to delete views. 
 The last one is my favorite as it has most flexibility. */
proc delete data=work.a work.b (memtype=view); 
run;

proc sql;
    drop view work.a, work.b;
quit;

proc datasets lib=work nolist nowarn;
    delete a b / memtype = view;
run; quit;

proc datasets lib=work nolist nowarn memtype=(data view);
    delete a b;
run; quit;

No comments: