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;

Saturday, March 19, 2011

DROP variable

Continued - dropping variables
Instead of wanting to keep just a handful of variables, it is possible that we might want to get rid of just a handful of variables in our titanic data file. Below we show how we could get rid of the variables pclass and name.


data mylib.titanic;
set mylib.titanic;
drop pclass name;
run;
proc contents data=mylib.titanic;
run;
proc print data=mylib.titanic;
run;

KEEP variable

Continued Keeping variable
Our titanic data file had many many variables, say16, but we only care about just
a handful of them, pclass survived name. We can subset our data file to keep just those variables as
shown below.

data mylib.titanic;
set mylib.titanic;
keep pclass survived name;
run;
proc contents data=mylib.titanic;
run;
proc print data=mylib.titanic;
run;

Tuesday, March 15, 2011

Scatter diagram

Hai dear friends...Its me Anton...
actually I am not confident about blogging..and i dont konw is this the way to post some thing on blogg..
Any way please try this on SAS. its pretty intresting..
You just pick Titanic data from the library and follow this..
proc print data=____.titanic;
run;
proc gplot data=____.titanic;
plot fare*age;
run;


if you got thjis please reply me..
waiting for your reply..

Monday, March 7, 2011

Sorting of data


Sorting is a very important technique. To get certain information from our data we need to use sorting technique. Now we are going to study how to sort given data in SAS...
Consider the data give below
id         age      sex                   time
1          41        female             53
2          45        female             28
3          48        male                69
4          54        male                58
5          40        female             54
6          31        male                25
7          53        male                51
8          49        male                61
9          36        male                57
10        52        male                57

First you must create a library and save this data into a file. To sort data in SAS we can useproc sort”.Now  we are going to sort this data with respect to the variable “age”. Write down the following commands given below.

proc sort data=mylib.file1;
by age;
run;

This will sort our data in the ascending order. To sort in descending order use the following commands.

proc sort data=mylib.file1;
by descending age;
run;

You can sort this data with respect to more than one variables. That is, to sort this data with respect to “time” and “age” then try the codes below.

proc sort data=mylib.file1;
by time age;
run;

http://support.sas.com/documentation/onlinedoc/code.samples.htmltry this link you will get different data sets to download.

Wednesday, March 2, 2011

Data import


For accessing data which is in the form of "Excel spreadsheet(*.xls)",the following
procedure can be used in SAS.

libname test C:\mysas\; /*Assigns a library named test on location C:\mysas\*/
proc import out=test.data1/*set data1 as the name for new data on "test" library*/
datafile="C:\..\data.xls" /*Location of the datafile to be imported*/
dbms=excel replace;
sheet="sheet1$"; /*specifies the sheetname to be read*/
getnames=yes; /*to get the variable names from the first row of data*/
mixed=no; /*to convert numeric values to characters in a mixed type column*/
scantext=yes; /*to use the largest text size in a column as sas variable length*/
usedate=yes; /*use DATE. format for a Date/Time column*/
scantime=yes; /*use TIME. format if only time values found in a column*/
run;
Similarly,for accessing a Tab Delimited(*.txt) file:


libname test C:\mysas\; /*Assigns a library namest test on location C:\mysas\ */
proc import out=test.data1 /*set data1 as the name for new data*/
datafile="C:\..\data.txt" /*Location of the datafile to be imported*/
dbms=tab replace;
getnames=yes; /*to get the variable names from the first row of data*/
datarow=2; /*to select the row on which data starts*/

run;
And for getting a Comma Seperated Values(*.csv)file:

libname test C:\mysas\; /*Assigns a library namest test on location C:\mysas\ */
proc import out=test.data1 /*set data1 as the name for new data*/
datafile="C:\..\data.csv" /*Location of the datafile to be imported*/
dbms=csv replace;
getnames=yes; /*to get the variable names from the first row of data*/
datarow=2; /*to select the row on which data starts*/

run;

Tuesday, March 1, 2011

FORMAT command


Consider the data given below
Name              Gender
John                           1
Ram                            1
Geetha                      0
Nithin                        1
Meena                       0

In this data ‘0’ and ‘1’ represents “ Female” and “Male “ respectively. We need to change those 0’s and 1’s by their respective labels. For this we can use FORMAT command in SAS.

libname mylib "D:\sas\";/*Creating a library named mylib*/
data mylib.file1;/*Storing the given data into file1*/
input name$ gender;
datalines;
John 1
Ram 1
Geetha 0
Nithin 1
Meena 0
;
run;
proc format;/*Creating a format named sex*/
value sex
0='female'
1='male'
;
run;
proc print data=mylib.file1;
format gender sex.;/*Format is applying  to the variable gender*/
run;


These codes can only format the output. If you want to make changes in the file, use the follwing code given below.

data mylib.file1;
set mylib.file1;
format gender sex.;
run;

If you are using “ data mylib.file2; ” instead of “ data mylib.file1; ” then SAS will create a new file named ‘file2’ and a formatted version of this data will save into it.