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 Retain
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 Retain

Introduction to SAS Retain

The SAS Retain is one of the statements that can be used for copying and retaining the values by using the SAS not to reset the variables for missing at the beginning stage of the data iteration that will calculate the variables and would keep the value assigned at once unless and until the assignment will explicitly change data value, data read along with input set.

SAS Retain

What is SAS Retain?

The Retain statement copies from retaining the values by using the SAS, not resetting the variables. It will be missing at the beginning stage of each iteration at the DATA step; the SAS would return at the beginning iteration values of each dataset missing once the value is assigned. SAS data set of each unique and multiple set of records observed at the record details must be compared from one record to another. It calculates the number of days for performing the user operations, which Retain the statement at the beginning of SAS programmers. SAS data is the usual way to stop and read the data value, which realizes that there are no more data values to be read.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

SAS Retain Statement

A Retain statement tells the SAS that it does not set the missing values assigned to the variables during each data step iteration. Instead, it will specify the variable names which sustain and retain the values of all the variables created in the Input or assignment statement. SAS sets the initial value of the variable that retained the data missing if we specified the initial value. Understanding the Retain values and statements that can be implicitly retained in the data step is essential. It is not an executable statement; therefore, it can appear anywhere in the Data step; it remembers the values from the previous set of observations that were accomplished to the SAS datasets default. The statement was also simplified using the copied retain values not to reset the variables, which we missed at the beginning stage of each iteration in the data step.

If we have not mentioned the retain statement, then the SAS would be returned, and the variables would reset at the beginning of the data step. Retain statement will keep the value once we assign the serial number or row the index number with the data step. Suppose we have a group variable that needs to generate the row index number calculated using the calculations across the entire data set in the manipulation. It mainly keeps the data value from the current iteration; its used widely in expected and most often unnoticed data processing errors. SAS Retain statement allowed for keeping the values across the observations, which enabled the complex data errors and manipulations. It is quite forward to straight away the values from one observation to another dataset lab tests are performed from scheduled and unscheduled planned activity for problematic scenarios on the SAS code.

Steps to perform the retain statement

1. It causes the variable to create the input or assignment statement to retain the values from one iteration of the DATA step to the following variable.

2. Navigate to the below link.

3. https://odamid-apse1-2.oda.sas.com/SASStudio/main?locale=en_US&zone=GMT%252B05%253A30&ticket=ST-89690-maIx6tHWg2OBpEtReQ35-cas

4. Create the data set in the below format; here, I have taken employee details as an example.

5. DATA employees;

6. input empid 1-2 empname $ 5-9 empdept $ 12-13 empsnno 15-17;

7. cards;

8. 1 Siva CSE 12

9. 2 Siva IT 34

10. ;

11. RUN;

12.

13. PROC PRINT data = employees Res;

14. title ‘The employee’s data set’;

15. RUN;

SAS Retain - title 'The employee's data set';

16. It will create the data set like the one below.

create the data set

17. We can run the retain operation below with the above employee dataset.

employees dataset

Using SAS Retain

The data step searches using the data sets maintained by the programs and challenges the codes with different ways to search the data set. When SAS reads the last observation set of data, that can be iterated using the RETAIN statement to keep the data tracked from the lowest region to higher regions. Because the SAS would be otherwise, it can set the variables from upper to lower regions. Vice-versa, the automatic variables will be looked at in the data vector reshaping the datas from the wide-area to large breadth formats merging the datasets at the beginning of each iteration at the SAS places which missing the values from the programming data vector for variables assigned by either Input statement of the assigned variables with a statement from the DATA step. It does not reset the variables to assign the programming data vector, called the Input statement. Instead, it is created using the SUM statement of values from the SAS data set via SET or Merge statement.

Next, the SAS data is set up along with each step; after that, it will complete the data step iteration. The SAS outputs of the values assigned to the variables in the programming data vectors of the SAS data set, which is already created on the Output statement, allowed control of the observed data set written on the areas. The Retain statement helps cause the variables that already created the data step to retain their value from the data observation from old to current iterations.

Example of SAS Retain

Given below is the example of SAS Retain:

Code:

DATA employees;
input empid 1-2 empname $ 5-9 empdept $ 12-13 empsnno 15-17;
cards;
1 Siva CSE 12
2 Siva IT 34
;
RUN;
DATA second;
  set employees (where = (empdept in ('CSE', 'IT')));
RUN;
DATA adds (rename = (outs = empdept));
  set second;
  by empid;
  retain lower outs;
  if first.empid then lower = empsnno;
  lower = min(lower, empsnno);
  if empsnno = lower then outs = empdept;
  if last.empid then output;
  drop empdept;
RUN;
PROC PRINT data=adds;
  title 'Total output Dataset: adds';
RUN;

Output:

SAS Retain - created the data set in the first set of coded instructions

SAS Retain - set the proc data for setting the data transactions

  • In the above example, we created the data set in the first set of coded instructions, which helps create and declare the input variables.
  • Next, we set the proc data for setting the data transactions, which passes the transactions from lower or other ranges to the next level set of ranges.
  • We have used Retain statement as the keyword to compare the data set value from one attribute column to another.

Conclusion

The SAS retain is the type of keyword that helps compare the observations from the source set of data sets. It occupies the center set of data values from around the long values that are retained and the ability to need the variables that assign the values by using the Input statement for missing the iteration.

Recommended Articles

This is a guide to SAS Retain. Here we discuss the introduction, SAS retain statement, and examples for a better understanding. You may also have a look at the following articles to learn more –

  1. SAS Visual Analytics
  2. Data Architects
  3. Data Engineer Role
  4. SAAS Cloud
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
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

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