I have the below data and I need to create the table ( given below), I need some help how I would be able to do that.
data test;
input form $char2. CorrectAns $char2.;
cards;
0100
0100
0101
0104
0104
0301
0402
0402
04NS
04NS
;
run;
Below table is desired, should show how many students for a respective form have the correct answers.
example- there are 2 students in form1 who scored 00 and there is 1 student each in form1 and form 3 who scored 1. and so on.
N- number of student in exch form.(excluding the student whos correct answer is "NS".
finally Mean is the mean correct answers for each form.
Example- for Form1 , there are 5 students who scored- 0,0,1,4,4, mean 9/5=1.8.
| Form01 | Form02 | Form03 | Form04 |
CorrectAns |
|
|
|
|
0 | 2 | . | . |
|
1 | 1 | . | 1 |
|
2 | . | . | . | 2 |
3 | . | . | . |
|
4 | 2 | . | . |
|
N | 5 | . | 1 | 2 |
MEAN | 1.8 | . | 1 | 2 |
I am using 9.4, All your help is appreciated.
Thanks MKS2204
You can get all of your desired counts using proc freq. e.g.,
proc freq data=test (where=(CorrectAns ne 'NS')); tables correctans*form; run;
and you can include options to exclude most of the counts and percentages, as well as how to treat zeros as missing.
You can also use completetypes and preloadfmt (see: http://www.pharmasug.org/proceedings/2012/CC/PharmaSUG-2012-CC26.pdf ) to include the missing form.
However, you'll have to tell us more about the means you want, as I can't figure out where the 1.8 came from.
Art, CEO, AnalystFinder.com
Thank you @art297
I tried freq but I wanted to get all the forms on a row , the way I had the table in example.
And how I got mean 1.8 for Form1 , there are 5 students for form1 who scored- 0,0,1,4,4 (2 student scored 0, one student scored 1 and 2 student scored 4) 0+0+1+4+4=9. Mean 9/5=1.8.
Hope I make sense.
MKS22044
Try proc freq using the code I suggested (but, if you want the missing values included as well, modify to include the other options I mentioned. The crosstab table it provides does produce the table you described.
Art, CEO, AnalystFinder.com
Thanks @art297 , I was able to create the report I needed.
Do you need a dataset or a report?
@ballardw Thanks you !
A report, can be xls or html.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.