EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials SAS Tutorial SAS KEEP
 

SAS KEEP

Updated March 16, 2023

SAS KEEP

 

 

Introduction to SAS KEEP

SAS keep is one of the statements that can be helpful to cause the data to be written in various ways and then we created a dataset by using the variable declaration for more than one SAS dataset like that Keep is the keyword for to apply all these things to SAS datasets and appear at anywhere of the area SAS Proc the procedure which includes and exclude the output datasets.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

What is SAS KEEP?

Keep is the keyword and it acts as the SAS statement to write the variables that must be declared already on more than one dataset. It can be called in everywhere and anywhere of SAS datasets, without a keep statement means all the datasets are created under the data step that includes all the variable types so that the keep and drop keyword will not use the same data step. To list the variable with specified number and name of the variables that can be written on the output dataset. When we set the Keep=data set option the data is automatically associated with the input dataset, and that can be called and listed by using this option.

How to use Data Set in Keep?

Generally, keep statement cannot be used in the SAS Procedure with step-by-step calls once the keep= dataset option is declared. We need to follow up the same in both input and output datasets with the same variable or different variables for processing the entire application area. Keep keyword is used with anywhere application and it specifies the variable name for writing the output dataset list. It is similar to the drop statement to parallelly execute at a  specified set of variables to omit the data set output. We can use the Keep and Drop statement at the same point of the level at the variable selection for including and excluding the output datasets. IF statement is the main point of view for selecting the data observations for Keep statement. It will be recovered at the Retain keyword to hold the SAS variable value from one point of iteration to the next iteration at the DATA step.

The Keep statement cannot be affected by the value of the variable but it depends on and specifies only the data variables which includes the output datasets. It can be specified into two different categories as below.

  1. We can choose which columns are to be used as KEEP statements because we must enter the dataset first and then set the original data so it does not vary from the dataset which was declared earlier using the Keep keyword and declaring the variables for performing the operation.
  2. Then we can choose the columns to DROP the statement as used for KEEP data set. Because the existing dataset variable values are dropped and created the new one.

Steps to Create and Use

1. Navigate to the below URL,
https://welcome.oda.sas.com/login

2. Paste the below code for creating the dataset,
3. data first;
4. input month $ date year;
5. datalines;
6. January 21 2022
7. February 22 2022
8. ;
9. run;
10.
11. proc print data=first;

SAS KEEP 1

12. data second;
13. set first;
14. keep date year;
15. run;
16.
17. proc print data=second;

SAS KEEP 2

Image 3

SAS KEEP Statement

We want to retrieve the dataset variable by using the KEEP = option to perform the choices at the specified variables. To read the input data set we want to keep the existing data variable for writing the outputs on the mentioned dataset. If we used the KEEP = option that should be placed on the parentheses for variable selection that keeps separated from the blank space it should be needed at least one on the specified inputs.

We can create the temporary dataset depending upon the variable selection to read the SAS inputs from the temporary dataset which is already stored on the new dataset.

So that they keep statements for keeps the variables whichever you want to keep the input values on the required dataset. We can keep the numeric set of variables by using the KEEP statement.

SAS KEEP vs Drop

                             KEEP                                  Drop
In SAS dataset the set statement the keep= is the option to read and determine the inputs In SAS dataset the set statement the drop= is the option to read and determine the inputs
It excluded the variables for not reading the data vector Same as keep for to exclude the variable in the programming data vector
It cannot be used as the SAS Procedure It also not used in the SAS Procedure
It is mainly helpful for to keep the variable values in the data set It helps to drop the specified variables on the output dataset.
Output statements are named as the Keep= dataset option The output statements are omitted if the drop statement are executed parallelly

Example:

data first;

input month $ date year;

datalines;

January 21 2022

February 22 2022

March 23 2022

April 24 2022

May 25 2022

June 26 2022

July 27 2022

August 28 2022

September 29 2022

October 30 2022

November 31 2022

December 1 2022

;

run;

proc print data=first;

data second;

set first;

keep date year;

run;

Sample Output:

sample Output

In the above example, we have created a dataset first and then used the same dataset variables in the keep statement.

Here we created dataset for the Date, Month, and Year variables.

We can use the keep statement for Date and Month, so the values are retained from the original dataset to another dataset.

Key Takeaways

  • It can write only the variable specified in the dataset for one or more numbers.
  • It applies to all SAS datasets which must be created on the Same Data Step.
  • It can be used anywhere on the SAS programming code.
  • It cannot be used as the SAS Procedure.
  • It does not affect the variable values, but it only specified the variables to include in the output datasets.

Frequently Asked Questions

Below are the FAQs as mentioned.

Q1. What is SAS keep?

Answer: It is one of the SAS statements that can be used to write the variables on the SAS output datasets.

Q2. How do you use Keep in SAS?

Answer: Keep=option is applied before the Rename=option statement so that the output datasets are evaluated from the left to right position on the Data statement.

Q3. How do we keep only certain columns in SAS?

Answer: By using Select variables and keyword Keep=-option which starts and followed with the equal operator, finally the variables want to be selected.

Conclusion

SAS keep is like the statement that helps to declare and keep the data variables along with the values to keep the position as same as the original datasets. We can use more than one variable at the time we separate the data in the blank space in the inputs.

Recommended Articles

This is a guide to SAS KEEP. Here we discuss the Introduction, What is SAS KEEP, How to use Data Set in SAS keep, and examples with code implementation. You may also have a look at the following articles to learn more –

  1. SAS Triangle Calculator
  2. What is SAS Grid?
  3. How to Use SAS Find?
  4. Steps to create SAS boxplot

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW