Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sentry Page Protection
Please Wait...
SAS Functions [13-14]


RENAME, KEEP & DROP STATEMENTS

You can change the name of a variable using the RENAME statement. 
Picture

The variable names in this data set (i.e. FIRST_NAME, LAST_NAME and PARTICIPANTS_AGE) are particularly long.

We can rename the variable names using the RENAME statement. 

Example

Data Profile2;
Set Profile;
Rename First_Name = First
       Last_Name = Last
       Participants_age = age;

Run;
Picture

Note: it is highly recommended to name the variable in no more than 8 characters. 

Long variable name not only takes longer to type but also leads to more programming errors.


KEEP & DROP STATEMENTS

The KEEP and DROP statements allow you to, well, keep and drop variables!

The two examples below create the exact same data set:

Example

Data Profile2;
Set Profile;
Keep First_Name Last_Name;
Run;

Data Profile2;
Set Profile;
Drop Participants_age;
Run;
Picture

Exercise

Locate the MARGARIN data set from the SASHELP library.

The MARGARIN data set contains 7 variables.

Write a SAS program to create a data set that contains only the HOUSEID, CHOICE and BRAND variables. 

Rename the HOUSEID variable to just ID. 
Next

Need some help? 


HINT:
The KEEP statement is the better function to use when there is a small number of variables to keep in the data set.


SOLUTION:
Data Margarin;
Set SASHelp.Margarin;
Keep HouseID Choice Brand;
Rename HouseID = ID;
Run;


Fill out my online form.

Already a member? Go to member's area.