To correct the problem in , you can use a RETAIN statement to initialize the value of SUBJECT to a non-missing value (0 for the first observation), and then bring forward the previous value of SUBJECT to each new observation being added to the data set you are building.
You then increment the value of SUBJECT by 1 for each observation. If you place the following line anywhere in the DATA step, the program executes as desired and produces the results shown in Output 2:RETAIN SUBJECT 0;
Output from Example - Creating a Subject Number in the DATA Step Using RETAIN
You may be asking yourself why you went through the trouble of producing the variable SUBJECT when the system provides OBS in the PROC PRINT output, and this is exactly the value you worked so hard to obtain.
The answer is that OBS is a display variable only.It is not included in the data set; it is only present in the PROC PRINT output.By using the method shown here, you have the value of SUBJECT as part of the data set itself. Of course, if the OBS number on the output is all you'll ever need, by all means use what the system gives you and don't create extra work for yourself.
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.