![]() ![]() ![]() However, since SAS processes data row-by-row, you can use this method to calculate a rolling weighted average.Īs mentioned, SAS processes data row-by-row and “forgets” everything about the previous row when it starts processing a new row. This method is the most complicated and requires the most code. The fourth method to calculate the weighted average is with a SAS Data Step. PROC UNIVARIATE Output Dataset Method 4: Data Step After the name of the output dataset, you specify which statistics to include and how to call them. With the var keyword, you specify for which variable you want to calculate the sum and weighted mean.įinally, with the output keyword, you create an output dataset ( work.weighted_average). In the second line, you use the weight keyword to let SAS know to calculate the weighted mean instead of the normal mean. You also specify that you want to calculate the sum, the sum of weights, and the mean. In the first line of code, you call the PROC MEANS procedure and define the input data ( work.my_data). However, with some modifications, you can use PROC MEANS also to calculate the weighted mean. By default, it shows you the number of observations, the mean, the standard deviation, the minimum, and the maximum for each numeric column. PROC MEANS is a common and powerful SAS procedure to quickly analyze numerical data. The second method to calculate the weighted average is with PROC MEANS. Otherwise, it will create a SAS table with the weighted average. If you omit this statement, SAS will only create a report. You can decide to include the CREATE TABLE statement, depending on your needs. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |