DATASTEP OPTIONS IN SAS

DATASTEP OPTIONS ARE:

1.Drop
2. Keep
3.Rename
4.Firstobs
5.Obs
6. Index
7.Label
8.Pw(password)
9.Where

/*1.Drop data step option*/

Excludes variables from processing or from output SAS data sets.
Valid: DATA step and PROC steps.
In DATA steps, the DROP= data set option can apply to both input and output data sets. 
The DROP statement applies only to output data sets.;
/*Ex*/
data est(drop= rept); /*input data set*/
input  sid$ motif$ rept;
datalines;
A00010  AC  5
A00010 TA   6
A00010 GC  3

run;
Drop statement along with set statement: ;
eg:
Data temp;
Set est (drop =sid);/*output data set*/
Run;

/*Drop can be used in proc steps.*/
eg:
Proc print data=EST (drop=motif);
Run;

/*2.Keep= Data Set Option*/

Specifies variables for processing or for writing to output SAS data sets
Valid: DATA step and PROC steps.;
In DATA steps, the KEEP= data set option can apply to both input and output data sets. The KEEP statement applies only to output data sets.In PROC steps, you can use only the KEEP= data set option, not the KEEP statement.
placed in parentheses following data set name and applies 
to that data set only. 

*eg*
data  est1(keep=sid motif ); /*input data set*/
Input sid$ motif$ rept;
Datalines;
A00010   AC   5
A00010  TA    6
;
Run;

/*Keep= option with SET Statement:*/
eg:
Data est2;
   Set est1(keep=sid); /*output data set*/
   Bonus=sid*1.1;
Run;

/*keep can be used in proc steps.*/
eg:
Proc print data=EST (keep=motif);
Run;

/*3.RENAME= Data Set Option:*/

Changes the name of a variable.
The RENAME= data set option can be used in PROC steps and the RENAME statement cannot.
To rename variables before processing begins, 
you must use a RENAME= data set option on the input data set or data sets.
Valid: DATA step and PROC steps.
Syntax:
RENAME= (old-name-1=new-name-1);
Old-name is The variable you want to rename. 
New-name The new name of the variable. 
It must be a valid SAS name.;
/*Ex:*/
Data est2 (rename= (sid=seq_id ));
Input Sid$ motif$ rept;
Datalines;
A00010   AC   5
A00010 TA    6
;
Run;

/*Rename= option with SET Statement:*/
eg:
Data est3;
   Set est2(rename=(motif=mottif_n)); /*output data set*/
   Run;

/*Rename can be used in proc steps.*/
eg:
Proc print data=EST2 (rename=(rept=rept_n));
Run;

/*4.FIRSTOBS= Data Set Option:*/

Specifies which observation SAS processes first.
Valid: DATA step and PROC steps.

/*Syn:*/
FIRSTOBS= MIN | MAX | n|.
/*note*/
in input data set firstobs=data option not valid it works on already existing data set.
The FIRSTOBS= data set option affects a single, 
existing SAS data set. Use the FIRSTOBS= system option to 
affect all steps for the duration of your current SAS session.
You can apply FIRSTOBS= processing to WHERE processing.;

/*firstobs= option with SET Statement:*/
/*Ex*/
Data Temp;
  Set EST (firstobs=3);
Run;

/*We can apply First obs in proc step.*/
eg:
Proc print data=EST (firstobs=2);
Run;

/* firstobs= option with input data set not valid*/
Data est2; (firstobs=3);
Input Sid$ motif$ rept;
Datalines;
A00010   AC   5
A00010 TA    6
A00010   AC   7
A00010 TA    8
;
Run;

/*5.OBS= Data Set Option*/

Specifies which observation SAS processes last.
Syntax
OBS= MIN | MAX | n;
This option specifies the number of the last observation to process, not how many observations should be processed. 
/*It is valid only when an existing SAS data set is read.*/
The OBS= data set option overrides the OBS= system option for the individual data set.While the OBS= data set option specifies an ending point for processing, the FIRSTOBS= data set option specifies a starting point.
You can select observations to be read from external
data files by using the OBS= option in the INFILE statement.;

/*obs= option with SET Statement:*/
/*Ex*/
Data new;
Set a (obs=10);
Run;

/*How to apply in Proc step both firstobs= obs=options   .*/
eg:
Proc print data=a (firstobs=4 obs=15);
/*starting at 4th obs end with 15th obs a has total 19 observations*/
Run;

/*6.INDEX=DATASET OPTION*/
    
Defines indexes when a SAS data set is created.;
syn:
Data dsn (INDEX=(variblename/index-specification-1 ...<index-specification-n>) );
dsn=data set name
/*Ex*/
Data est1 (index=(sid/unique ));
input  sid$ motif$ rept;
datalines;
A00010   AC   5
A00011   TA   6
;
run;

/*7.LABEL= Data Set Option:*/
     Specifies a label for the SAS data set.
The LABEL= data set option enables you to specify labels only for data sets. You can specify labels for the variables in a data set using the LABEL statement. 
The LABEL= option in the ATTRIB statement also enables you to assign labels to variables. 
Label is a text string of up to 256 characters.
/*Syn*/
Data dsn (LABEL='label');
dsn=data set name
/*Ex*/
this label can be view on view table only 
Data  est (label='Expressed Sequence Tags');
Input sid$ motif$ rept;
datalines;
A00010   AC   5
A00010  TA    6
;
run;

proc print;
run;

/*8.PW= Data Set Option:  */
Assigns a read, write, or alter password to a SAS file and 
enables access to a password-protected SAS file.
Valid: DATA step and PROC steps.
The PW= option applies to all types of SAS files except catalogs. 
You can use this option to assign a password to a SAS file or to access a password-protected SAS file.;
/*Ex*/
Data  est (PASSWORD=TIGER);
Input sid$ motif$ rept;
datalines;
A00010   AC 5
A00010  AC  6
A00011  TC  7
;
run;

/*9.WHERE= Data Set Option*/

Use the WHERE= data set option with an input data set to 
select observations that meet the condition specified 
in the WHERE expression before SAS brings them into 
the DATA or PROC step for processing. Selecting observations
that meet the conditions of the WHERE expression is the first 
operation SAS performs in each iteration of the DATA step. 
You can also select observations that are written to an output data set.
The WHERE statement applies to all input data sets, 
whereas the WHERE= data set option selects observations only from 
the data set for which it is specified. 

/*Ex*/
Data  est1 (WHERE=(MOTIF='AC'));
Input sid$ motif$ rept;
datalines;
A00010   AC 5
A00010  AC  6
A00011  TC  7
A00011  TC  8
;
run;

/*Where= option with SET Statement:*/
eg:
Data estn;
   Set est3(where=(rept=6)); /*output data set*/
   Run;

/*Where= can be used in proc steps.*/
eg:
Proc print data=a (where=(age=14));
Run;