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.

No comments:

Post a Comment