In this example,each subject answered 50 items in a psychological survey. Each question is scored on a 1 to 5 scale.To ensure that an accurate assessment is made, the mean score is computed only if 40 or more items were answered.Your job (should you choose to accept it) is to compute the mean of the 50 scores (ITEM1-ITEM50), but only if at least 40 items are nonmissing. Here is the program:
As you probably figured out by inspecting this program, the N function returns the number of non-missing values in the variable list, and the MEAN function returns the mean of the nonmissing values in the variable list.Actually, you may not have figured out the importance of the way the MEAN function deals with non-missing values, and this is quite important.If you calculate SCORE by simply adding up all the items and then dividing by 50 as follows:SCORE=(ITEM1 + ITEM2 + ITEM3 + ... + ITEM50)/50;
you would be in big trouble if any of the items had missing values. When a SAS statement tries to do arithmetic operations on missing values, the result is always missing.Countless hours have been (and undoubtedly will be) spent trying to figure out why seemingly perfect code continues to yield empty results.Now you know why.
You also know that the MEAN function computes the mean of the non-missing values and, therefore,always yields a valid result (unless of course all the data values are missing).In addition to the N and MEAN functions, the functions NMISS and SUM operate in a similar manner, with NMISS returning the number of variables with missing values and SUM returning the sum of the non-missing values.
The complementary pair of functions MIN and MAX are also useful and, as you would expect, return the minimum and maximum values in the argument list respectively.
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.