Thursday, April 14, 2011

The CLASS Variable

We can use the variable CLASS in the place of BY in our 'SAS Assignment 1' for obtaining the output in a same table.
ie;
in the place of
proc means data=mylib.Assessment sum mean ;
by x1;
run;
we can use
proc means data=mylib.Assessment sum mean ;
class x1;
run;

Tuesday, April 12, 2011

MERGE Command

When you want to match observations from one dataset with observations from another, use the MERGE statement in the DATA step.

Merging SAS data set is a simple process. First, if the data are not already sorted, use the SORT procedure to sort all data sets by the common variables. Then, in the DATA statement, name the new SAS data set to hold the results and follow with a MERGE statement listing the data sets to be combined . use a BY statement to indicate the common variables. For an example,

We have 2 datasets a and b.

First dataset -a. It contains

Name score1

Anu 34

Raju 38

Ravi 56

Anna 21

Second dataset –b it contains

Name score2

Anu 35

Raju 39

Ravi 58

Anna 25



I need a data set with name, score1 and score2 .

data mylib.dataone;

input name$ score1;

datalines;

Anu 34

Raju 38

Anna 56

Ann 21

;

run;

data mylib.datatwo;

input name$ score2;

datalines;

Anu 35

Raju 39

Anna 57

Ann 28

;

run;

proc sort data=mylib.dataone;

by name;

run;

proc sort data=mylib.datatwo;

by name;

run;

data mylib.data;

merge mylib.dataone mylib.datatwo;

by name;

run;

proc print data=mylib.data;

run;

Monday, April 4, 2011

SAS Assignment 1

Question 1
● Use the Base SAS windowing environment to write and submit a simple SAS program
● Given the data set:

Salesperson ,
Target company,
Number of visits,
Number of phone calls,
Units sold,

Brown American 3 12 28000
Johnson VRW 6 14 33000
Rivera Texam 2 6 8000
Brown Standard 0 22 0
Brown Knowles 2 19 12000
Rivera Metro 4 8 13000
Rivera Uniman 8 7 27000
Johnson Oldham 3 16 8000
Johnson Rondo 2 14 2000

1. Write a SAS program to compare the sales records of the company’s three sales people –
that is, compute the sum and mean for the number of visits, phone calls and units sold for
each salesperson.

ans;

libname mylib'E:\ast';
data mylib.Assessment;
input x1$ x2 x3 x4 x5;
datalines;
Brown American 3 12 28000
Johnson VRW 6 14 33000
Rivera Texam 2 6 8000
Brown Standard 0 22 0
Brown Knowles 2 19 12000
Rivera Metro 4 8 13000
Rivera Uniman 8 7 27000
Johnson Oldham 3 16 8000
Johnson Rondo 2 14 2000
;
run;
data mylib.Assessment;
set mylib.Assessment;
label x1='Salesperson'
x2='Target company'
x3='Number of visits'
x4='Number of phone calls'
x5='Units sold'
;
run;
proc print data=mylib.Assessment;
run;
proc sort data=mylib.Assessment;
by x1;
run;
proc means data=mylib.Assessment sum mean ;
by x1;
run;