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;

Saturday, March 26, 2011

Correlation in SAS


To establish the linear  relationship between two variables  we can use correlation. We can use PROC CORR  in SAS to do this. The syntax is given below,

proc corr data=mylib.file1;
var variable1 variable2;
run;

This code will give the Pearson's Correlation Coefficient.  To find another correlation coefficient like Spearman’s , Kendall, etc... just type

proc corr data= mylib.file1 spearman;

If you want to find both of them in a single expression 

proc corr data= mylib.file1 spearman pearson;

Try these codes and give your feedback. Download different SAS data sets try these types of operations into it. You can visit http://www.principlesofeconometrics.com/sas.htm to download SAS data sets

Wednesday, March 23, 2011

Q-Q Plot


Now  we’re going to learn how to create Q-Q Plot. It is ver simple, just try the codes given below.

proc univariate data=library_name.file_name;
var variable_name ;
qqplot;
run;


or just try,

proc univariate data=.;
qqplot variable_name;
run;

the above code will creat a Q-Q Plot of a particular variable.
If you want Q-Q Plot of two varibles the rewrite the above command with

qqplot variable1 variable2;

Similar manner you can try with any number of variables

Sunday, March 20, 2011

Box Plot

Pls try with our titanic data

proc sort data=mylib.titanic;
by increasing fare pclass;
run;
proc boxplot data=mylib.titanic;
plot fare*pclass;
run;

Plot histogram with normal curve and inset option

proc univariate data=mylib.titanic1;
title "Histogram for variable fare";
histogram fare/cfill=ligr normal cframe=liy barwidth=8 cv=black;
inset mean std max min;
run;