BookmarkSubscribeRSS Feed
MKS2204
Obsidian | Level 7

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

7 REPLIES 7
art297
Opal | Level 21

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

 

MKS2204
Obsidian | Level 7

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

art297
Opal | Level 21

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

 

MKS2204
Obsidian | Level 7

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

 

ballardw
Super User

@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.

ballardw
Super User

Do you need a dataset or a report?

MKS2204
Obsidian | Level 7

@ballardw Thanks you !

A report, can be xls or html.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1018 views
  • 0 likes
  • 3 in conversation