EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials SAS Tutorial SAS KEEP
Secondary Sidebar
SAS Tutorial
  • Basic
    • What is SAS
    • Advantages of SAS
    • Career in SAS
    • SAS Command
    • SAS Operators
    • SAS Export to CSV
    • Loops in SAS
    • DO WHILE in SAS
    • SAS System Interview Questions
    • SSAS Interview Questions
    • SAS Visual Analytics
    • SAS Join
    • SAS Length
    • SAS INTNX
    • SAS Congruence
    • SAS LAG Function
    • SAS boxplot
    • SAS INTCK
    • SAS Find
    • SAS Grid
    • SAS Triangle Calculator
    • SAS KEEP
    • SAS YEAR Function
    • SAS Format
    • SAS Libname
    • SAS Rename
    • SAS Retain
    • SAS Base
    • SAS JMP
    • SAS Array
    • SAS Round
    • SAS DO Loop
    • SAS Index
    • SAS Datalines
    • SAS Model
    • SAS Logistic Regression
    • SAS Numeric to Character
    • SAS Label
    • SAS ODS
    • SAS Upcase
    • SAS Numeric Formats
    • SAS Nodupkey

SAS KEEP

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.

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.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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
Popular Course in this category
SAS Training (9 Courses, 10+ Projects)
  9 Online Courses |  10 Hands-on Projects |  123+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Data Visualization Training (15 Courses, 5+ Projects)4.9
Business Intelligence Training (12 Courses, 6+ Projects)4.8
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - 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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*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?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more