Proc datasets tips
28. July 2007 11:46
Splitting the data.frame into 3 parts
/* 1. list contents of last dataset used, en3 */
/* 4. proc datasets version of above - list all datasets in the specified library */
/* 14. append datasets - note this is quicker than using a set command, as only the appended dataset is read in */
data en1(drop = course) en2 en3; set deet07.dx2007; if 0 <= _N_ <= 1000 then output en1; else if 1000 < _N_ <= 2000 then output en2; else if 2000 < _N_ <= 3000 then output en3; run;
/* 1. list contents of last dataset used, en3 */
proc contents data= _LAST_; run;
/* 2. list contents of all datasets in the work library */ proc contents data=work._ALL_; run; /* 3. list datasets in the work library */ proc contents data=work._ALL_ nods; run;
/* 4. proc datasets version of above - list all datasets in the specified library */
proc datasets library=work; quit; run; /* 5. describe a single dataset */ proc datasets library=work; contents data=en1; quit; run; /* 6. describe all work datasets */ proc datasets; contents data=_ALL_; quit; run; /* 7. copy all datasets in work to stud07, excluding e3*/ proc datasets; copy in=work out=stud07; exclude e3; quit; run; /* 8. delete everything in work (deletes datasets and formats) */ proc datasets library=work kill; quit; run; /* 9. delete just the datasets */ proc datasets library=work memtype=data kill; quit; run; /* 10. move all datasets except en3 from stud07 to work */ proc datasets; copy move in=stud07 out=work; exclude en3; quit; run; /* 11. move just one dataset from stud07 to work */ proc datasets; copy move in=stud07 out=work; select en3; quit; run; /* 12. delete an individual dataset */ proc datasets library=work; delete en3; quit; run; /* 13. change the name of a dataset */ proc datasets library=work; change en2=en4; quit; run;
/* 14. append datasets - note this is quicker than using a set command, as only the appended dataset is read in */
proc datasets library=work; append out=en4 data=en1; quit; run; /* 15. rename a variable */ proc datasets library=work NOlist; modify en1; rename student=personid course = course_cd; run; quit;

Email 