Friday, May 8, 2009

How to delete or remove previously assigned formats and informats completely from the SAS dataset:

How to delete previously assigned formats and informats completely from the SAS dataset:

PROC DATASETS lib=work;
MODIFY dsn;
FORMAT _all_;
INFORMAT _all_;
RUN;
QUIT;

*work is the library name;
*mention the name of the SAS dataset, whose formats and informats needs to be removed in the MODIFY statement;
* format _all_ will delete all the formats in the SAS dataset.

*If you want to remove formats and informats for specific variables from the dataset, you can do that using PROC DATASETS and here is how?

*The following code will remove only the formats and informats of specific variables in the SAS dataset.

Proc DataSets Lib = Work;

Modify dsn;
Format heigt weight sex;
Run ;
Quit ;

*If we want to delete formats/informats of all character or numeric varibles, here is the way to do it;

**The following code will remove formats and informats for all the character variables in the SAS dataset.
proc datasets lib=work;
modify dsn;
format _char_; *format _num_;
run;
Quit;


********************************************************************************;
Another way to achieve same result is to use datstep with a SET statement and format/informat statements; In this method the order of SET, FORMAT and INFORMAT statements or important. Always follow the same order.

*The following code will remove all the formats and informats in the SAS dataset.
data dsn;
set dsn;
FORMAT _all_;
INFORMAT _all_;
run;

Using the datastep with the SET statemnt, we can also delete the formats and or informats of variables specifically from the SAS dataset.

*The following code will remove only the formats and informats of specific variables in the SAS dataset.
data dsn;
set dsn;
Format heigt weight sex;
INFORMAT weight sex;
run;

6 comments:

Anonymous said...

Simple concept. We are not assigning any format. So indirectly we are removing formats. Its very good question and answer. Keep it up.

Anonymous said...

how to remove for all the datasets in a library instead of mentioning one by one dataset name?

sarath said...

proc datasets library=work kill;
run;
quit;

The KILL option in Proc Dataset deletes all members of the library immediately after the statement is submitted. use your libname instead of work if you want to delete any permanent datasets from any library.

Post a Comment

ShareThis