I. Data Preparation: Program Examples

Several examples are shown here of creating and reading/accessing data sets for: 1) Permanent SAS data sets, 2) Temporary SAS data sets, and 3) Raw data sets.

1) Permanent SAS Data Sets

*************************************************
*This program CREATES a permanent SAS data set  *
*it assumes that a temporary SAS data set has   *
*already been created during the SAS session.   *
*************************************************;

libname sasref 'c:\sasdir';
    /* where to store the new permanent SAS data set*/

data sasref.new;   
       /* create a permanent SAS data set in the 
          sasdir directory */
       
  set htwt;     
       /* access, or read, a temporary SAS data set*/
       
run;
***************************************************
*This program READS a permanent SAS data set,     *
*creating a temporary SAS data set.               *
***************************************************;

libname sasref 'c:\sasdir';  
    /* location of permanent SAS data set on C: drive */

data one;  
     /* create a temporary SAS data set */

  set sasref.survey; 
     /* read the permanent SAS data set called "survey" */
run;

**************************************************
*The above program also CREATES a temporary SAS  *
*data set from a permanent SAS data set.         *
**************************************************;

2) Temporary SAS data sets

*************************************************
*This program READS a temporary SAS data set,   *
*creating another temporary SAS data set.       *
*It assumes that "one" has already been created *
*during the SAS session.                        *
*************************************************;

data two;
     /* create a temporary SAS data set called "two" */

  set one; 
     /* read the data set called "one" */

if gender='F'; 
     /* keep only females in the "two" data set */
        /* (this assumes the variable "gender" 
           exists in "one")*/
run;

3) Raw data sets


******************************************************
*This program CREATES a permanent SAS data set       *
*from a file containing raw data. (To create a       *
*temporary SAS data set, a libname is not needed.    *
*The libname would come out and the data statement*
*would be data one instead of data sasref.one).      *
*****************************************************;

filename rawref 'c:\sasdir
awdata'; 
  /* name and location of raw data file on C: drive */

libname sasref 'c:\sasdir'; 
/* location for new permanent SAS data set */

data sasref.one;    
  /* create a permanent SAS data at the sasref location*/
  infile rawref;
  input name $1-10
        sex $12
        sales 20-25;
run;


 << Previous

 Index

 Next >>