Saturday, March 10, 2012

INFORMAT IN SAS

To read a nonstandard data, we must use an informat
The general form of an informat is

<$>INFORMAT-NAME<w>.<d>

The commonly used Informats are

MMDDYYw.- Reads date in the form 12/19/2011
DATEw.        - Reads date in the form 19DEC2011
COMMAw.   - It reads numeric data($5,55) and strips out selected nonnumeric characters, such as dollar sign                                             and commas.


Sunday, March 4, 2012

Merging in SAS

For merging two data sets, we must sort the two data sets by a common variable.
let us consider the two data sets as data1, data2 and the common variable as id.Then after the processing in the data step , we can sort the two sets of data in the procedure step as follows.

proc sort data= mylib.data1;
by id;
run;

proc sort data= mylib.data2;
by id;
run;

After sorting the two data sets we can check whether they are sorted or not by the following procedure step

proc contents data=mylib.data1
run;

proc contents data=mylib.data1
run;

After sorting , we can merge the two data sets as follows

data mylib mdata;
merge mylib.data1 mylib.data2;
by id;
run;

proc print data =mylib.mdata;
run;


 

Monday, July 11, 2011

Data Importing

we can import the 'backpain data' by,

libname mylib'E:\ast';
data mylib.backpain;
PROC IMPORT OUT= MYLIB.BACKPAIN
DATAFILE= "E:\ast\backpain.txt"
DBMS=TAB REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;
proc print data=mylib.backpain;
run;

INFILE Command

INFILE command is used for importing data.
in our 'backpain' data , we can use the INFILE command as,

libname mylib'E:\ast';
data mylib.backpain;
infile'E:\ast\backpain.txt';
input a b$ c d;
run;
proc print data=mylib.backpain;
run;

Friday, May 6, 2011

Explore your library


Suppose you are working with a library named my_lib and you want to check how many datasets are under your library and which are they, to get this information use the following code given below,

proc datasets library=my_lib;
run;

Suppose you have two datasets DATA1, DATA2 under your library my_lib. If you want to check the contents in DATA2 use the following codes,

proc contents data=my_lib.DATA1;
run;

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;