Suppose you have a SAS data set EMPLOYEE which contains variables ID, DOB (date of birth),and several other variables. One requirement is to compute AGE from a date of birth. You have several choices to make.You can round the age to the nearest year or drop all fractional parts and take the age as of the last birthday.
You also need to consider as of what date you want the age computed.The example that follows is technically an approximate value for age,using the fact that an "average" year has 365.25 days (1leap year every 4 years). More sophisticated programming is needed to compute exact ages. First, let's look at ways to compute ages using the approximate method. Here is a program to compute a person's age several different ways:
AGE1 and AGE2 represent the age as of January 1,1995,with AGE2 rounded to the nearest year.These assignment statements use a date literal which is of the form: 'DDMMMYY'D DD is a two-digit day of the month, MMM is a month abbreviation, and YY is a two- or fourdigit year (it would be'DDMMYYYY'D in the latter case).
This string is placed in single or double quotation marks,followed by an upper-or lower-case D. SAS software will convert this literal into a SAS date (i.e. the number of days since January 1, 1960).Variables AGE3 and AGE4 are ages computed as of the current date which is represented by the TODAY() function.
The null parentheses () following the function name are required by SAS System syntax; all functions, even ones without any arguments, need parentheses so that the software can distinguish variable names from functions names.(Question: What did the TODAY function say to the MEAN function? Answer: "Don't give me any arguments!") Finally, AGE1 and AGE3 compute age as of the last birthday—the INT function truncates (throws away) the decimal part of the number.
AGE2 and AGE4 use the ROUND function to compute age to the nearest year.These functions are described in more detail in Example 3 in Chapter 5, "SAS Functions." We demonstrate an exact method to compute age later in this chapter.
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.