DATA Step, Macro, Functions and more

How would I create the table?

Reply
Occasional Contributor
Posts: 7

How would I create the table?

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

PROC Star
Posts: 7,366

Re: How would I create the table?

[ Edited ]

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

 

Occasional Contributor
Posts: 7

Re: How would I create the table?

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

PROC Star
Posts: 7,366

Re: How would I create the table?

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

 

Occasional Contributor
Posts: 7

Re: How would I create the table?

Thanks @art297 , I was able to create the report I needed.

 

Super User
Posts: 10,550

Re: How would I create the table?


MKS2204 wrote:

Thanks @art297 , I was able to create the report I needed.

 


Please post the code and mark that answer as the accepted solution.

Super User
Posts: 10,550

Re: How would I create the table?

Do you need a dataset or a report?

Occasional Contributor
Posts: 7

Re: How would I create the table?

@ballardw Thanks you !

A report, can be xls or html.

Ask a Question
Discussion stats
  • 7 replies
  • 131 views
  • 0 likes
  • 3 in conversation