sasinterviewsquestion

Just another WordPress.com site

SAS/SQL Interview Questions

Question

Dataset below shows the hospital visit by patients during the entire year (2012)

data hospital;

input name $ month $;

cards;

Tanu Jan

Tanoj Feb

Tanu Apr

Tanu Dec

Arun Oct

Kiran Nov

Tarun Mar

Tarun Apr

Tarun May

Tarun Dec

;

run;

Find out how many times each patient has visited the hospital in 2012-08-12 using proc freq, proc report, proc sql

 

Answer:

proc freq data = hospital;

tables name/out=hosp1(drop=percent);

run;

 

data hosp2;

set hospital;

count=1;

run;

proc report data = hosp2;

column name count;

define name/group;

run;

 

proc sql;

select name, sum(count) from hosp2 group by name;

quit;

 

Question:

data class;

input name $ subject $ marks;

cards;

Manoj Sacience 94

Raj Science 86

Tanu Maths 76

Manoj Maths 45

Manoj English 65

Tanu English 76

Tanu Science 76

Raj Maths 66

Raj English 56

;

run;

Use SQL to produce : Sum as

                                         

                                               204  Manoj

                                               208  Raj

                                               228  Tanu

 Avg Marks as:

 

                                          68  Manoj

                                          69.33333  Raj

                                          76  Tanu

Use proc means to do the same…

 

Answer:

proc sql;

select name, Avg(marks) from class group by name;

quit;

proc sort data = class;

by name;

run;

 

proc means data = class mean;

var marks;

by name;

run;

 

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 62 other followers

%d bloggers like this: