This example shows one of the pitfalls you can encounter when using RETAIN.Suppose you have recorded the date of birth and weight of each subject on three different weigh-ins.However,the date of birth was only recorded at the first weigh-in, and you were a little sloppy in your data collection and failed to get it for one of your subjects.You want to create a SAS data set that contains the subject's date of birth and weight in each observation.If any data are missing, they should be so noted. Here is the raw data file:
Here is a program that has all good intentions but doesn't give you exactly what you want:
Here is the output:
Output from Example - Using Caution When Coding with RETAIN
What Went Wrong?
The program was supposed to work in the following way: For each observation being added to the data set, DOB is read in from the raw data and OLD_DOB is created via a RETAIN statement O.In this example, you do not supply an initial value for the retained variable .
As each record is built for the data set, the values of DOB and OLD_DOB have an effect on each other.If DOB as read in is not missing (a new subject), then OLD_DOB is set to DOB @.If DOB is missing (another record for the previous subject),then DOB is set to the retained value of OLD_DOB ©. Sounds reasonable. So what went wrong? Since DOB was missing entirely for Subject 3, the retained value of OLD_DOB for Subject 2 was used (again).
SAS Programming Related Tutorials
|SASS (Syntactically Awesome Style sheets) Tutorial||R Programming language Tutorial|
SAS Programming Related Interview Questions
|Logistics Interview Questions||SAS Programming,SQL server Interview Questions|
|Clinical SAS Interview Questions||SASS (Syntactically Awesome Style sheets) Interview Questions|
|SQL Server Analysis Services (SSAS) Interview Questions||R Programming language Interview Questions|
|SAS DI Interview Questions||Advanced SAS Interview Questions|
|Base Sas Interview Questions||SAS Macro Interview Questions|
|Clinical Data Management Interview Questions|
Sas Programming Tutorial
Input And Infile
Set, Merge, And Update
Table Lookup Tools
Proc Means And Proc Uimivariate
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.