Secondly, you need the CLASS and VAR statements to calculate the average per group. But, because of its complexity, it gives you more flexibility to create beautiful reports. Proc print data=work.avg_by_group_3 noobs įirst of all, the syntax of PROC TABULATE is more complex than, for example, PROC SQL or PROC MEANS. Result = "Result" *(mean = "Avg." * format=comma12.2) run Proc tabulate data=work.exam_results out=work.avg_by_group_3 The table is ordered by the average result and the numbers are formatted with two decimals. The image below shows the new table created by the code above. If you want to group your data based on more columns, you separate the column names with a comma.įinally, we use the ORDER BY statement to order the average examen result in descending order. We want to calculate the average per student, so we use GROUP BY student. With the GROUP BY statement, we specify how to group the data to calculate the average. We use the FROM statement to specify which table to use for the calculations. Optionally, you can format the new column. Since we want to calculate the average result, the argument is the result column.Īfter the AS keyword, we define the name of the column that contains the average result. The function avg() calculates the average of its argument. Because we want to calculate the average result per student, we select the student column. With the SELECT statement, we define the columns of our new table. You can omit this statement if you only want to show the average per group on the screen without creating a new table. The statement is followed by the name of the new table ( work.avg_by_group_1) and the keyword AS. With the CREATE TABLE statement, we specify that we are creating a new table.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |