When there are many incidents of my id variables, I am thinking of the best way to transfer data to SAS. I know that I can use let option in the proc statement statement to do this, but I do not want to get rid of any data, as I want to calculate the average.
Here is an example of my data and my code:
data grade; Input Student Testonum Grade; Leaves; 1 1 30 1 1 25 1 2 45 1 3 67 2 1 22 2 2 63 2 2 12 2 2 77 3 1 22 3 1 17 3 2 14 3 4 17; Run; Proc Sort Data = Grade; By student Tsenum; Run; Proc transfer data = out of grade = trgrades; By student; ID Testonom; Grade of grade; Run; Here's how I want to see my resulting dataset:
student testnum1 testnum2 testnum3 testnum4 avg12 avg34 1 30 45 67 33.33 67 1 25. . 33.33 67 2 22 63. 43.5 2 12 43.5 2 77. 43.5 3 22 14 17 53 17 3 17. . 53 17 I want to use this new dataset (not sure how to do so) to create new columns, all the testnum1 average score and testnum2 student (avg12) For average and average one student all testenum3 and testnum4 (avg34)
may be a more efficient way to do this, but I'm getting stumped. Any advice is appreciated.
If you really need all, then all tests are an average of 1 and 2, and each student For 3 and 4, you do not need to move at all. All you need is a simple data phase:
grouped data; Prescribed grade; If testnum (1,2) then group = 1; And if (3,4) testnum then group = 2; Run; Then a basic proc means : proc data = grouped; By student group; Grade of grade; Output = average mean = grouping; Run; If you need an average in an overview, you can easily move the average dataset. proc transfer data = grade out = triggreds; By student; Id group; Grade of grade; Run;
Update:
As described by @ Keith, using the format for a set of tests is an excellent choice. Skip the data step and create the format like this:
proc format; Price TestGroup 1,2 = 'Test 1 and 2' 3,4 = 'Test 3 and 4'; Run; Then proc means : proc data = grouped; By student Tsenum; Grade of grade; Format Testonum Test Group.; Output = average mean = grouping; Run; and update
If, for some reason, you really need to get all the test scores in an overview, Recommend to make them specially recognizable. Use by , testnum.first , retention , and assign a recycling to each score Use Simple Counter for your id variable as your retak and testnum Does. Actually I am hoping that I have not done the work of SAS homework for you.
No comments:
Post a Comment