Posts

Showing posts with the label Proc Datasets

Renaming All Variables in a SAS Data Set Using the SASHELP VIEWS

*Create a temporary dataset... DSN; data dsn; a=1; b=2; c=3; d=4; e=5; f=6; run; % macro test(lib,dsn); */1)*/ data _null_; set sashelp.vtable(where=(libname=" &LIB " and memname= "&DSN" )); call symput( 'nvars', nvar); run; */2)*/ data dsn; set sashelp.vcolumn(where=(libname ="&LIB" and memname= "&DSN" )); call symput(cats( "var" ,_n_),name); run; */3)*/ proc datasets library =&LIB; modify &DSN; rename % do i = 1 % to &nvars; &&var&i=Rename_&&var&i. % end ; ; quit; run; % mend ; %test (WORK,DSN); After submitting the above program... the output looks like this.... Output: Rename_a Rename_b Rename_c Rename_d Rename_e Rename_f 1 2 3 4 5 6 Here is a way I know of.. to rename all the variables in the dataset; It can be done using the SASHELP views as follows: 1) The 1st step of the program determines the total number of variables inside the dataset with the help of SA...

Clean-Up: Delete datasets in the work library:

It is better always to clean-up/empty the work directory before we run the next set of SAS code. This is VERY helpful in situations where the “working” files created tend to use up a large amount of memory, once the logic of the program has been checked, KILLing the working files will result in a more efficient program. Another important reason to issue the above statement at the end of a program is when programs are run in batch, this will clean up the working library to be sure any “old” files are not left around to be erroneously used1. PROC DATASETS procedure offers an elegant solution to do just. Remember that there is no need of knowing any dataset names when we are emptying the work directory. Here is the simple syntax: proc datasets lib=work kill nolist memtype=data; quit; We have specified lib=work, because we are cleaning up the work directory. KILL option removes all the datasets that are happened to be in the work directory. NOLIST option tells SAS, printing the details...

Comparing Two Methods for Removing Formats and Informats in SAS: DATA Step vs. PROC DATASETS

Comparing Two Approaches to Removing Formats and Informats in SAS Comparing Two Approaches to Removing Formats and Informats in SAS When working with SAS datasets, there are times when you need to remove formats and informats that have been previously assigned to variables. Two primary approaches can be used for this task: Using the DATA Step Using the PROC DATASETS Procedure This article compares and contrasts these two approaches to help you determine which method is most appropriate for your needs. Approach 1: Using the DATA Step The DATA step is a versatile and commonly used method for removing formats and informats. By assigning variables to a null format or informat, you can effectively remove these attributes from your dataset. Example: data mydata_clean; set mydata; format _all_; informat _all_; run; In this example, the mydata dataset is processed in the DATA step, and...