Tuesday, March 11, 2014

SAS- File Operations read, write, append etc.

By Ajeet Kumar


/* File Reading Program Number: 1 */
/*list input style*/
DATA list ;
input Name $ Age Height ;
datalines;
Amit  22  111
Sumit 21 121                                
Mina 11 90
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 2 */
/*list input style*/
DATA list ;
input Name $ Age Height ;
datalines;
Amit    22
Sumit 21 121
Mina 11 90
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 3 */
/*list input style*/
DATA list ;
infile datalines ;
input Name $ Age Height ;
datalines;
Amit    22  111
Sumit 21 121
Mina 11 90
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 4 */
/*list input style*/
DATA list ;
infile datalines missover;
input Name $ Age Height ;
datalines;
Amit    22  111
Sumit 21
Mina 11 90
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 5 */
/*list input style*/
DATA list ;
infile datalines missover;
input Name $ Age Height State $;
datalines;
Amit    22  111 UK
Sumit 21 112 UP
Mina 11 90 MP
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 6 */
/*list input style*/
DATA list ;
infile datalines missover;
input Name $ Age Height State $;
datalines;
Amit    22  111 UK
Sumit 21 112
Mina 11 90 MP
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 7 */
/*list input style*/
DATA list ;
infile datalines stopover;
input Name $ Age Height State $;
datalines;
Amit    22  111 UK
Sumit 21 112
Mina 11 90 MP
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 8 */
/*list input style*/
DATA  ;
infile datalines stopover;
input Name $ Age Height State $ ;
datalines;
Amit    22e  111 UK
Sumit 21 112
Mina 11 90 MP
Ramesh 25 78 TN
Taimur 43 56 RS
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 9 */
proc contents data = class ; run;
data class1(drop = remarks);
set class ;
run;
proc print data = class1; run;
proc sql;
drop table class;
data class;
set class1;
run;

/* File Reading Program Number: 10 */
proc contents data = class ; run;
data class1(drop = remarks);
set class ;
run;
proc print data = class1; run;
proc sql;
drop table class;
data class2(label="Bharti Reported Data");
set class1;
run;
data Bharti Reported Data ;
set class1;
run;

/* File Reading Program Number: 11 */
data read;
infile "D:\SAS Class Sonam\Bharat.txt" missover;
input Name $ Gender $ State $ Age Height Weight ;
run;

/* File Reading Program Number: 12 */
data ;
infile "D:\SAS Class Sonam\Bharat.txt" obs = 3;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 13 */
data ;
infile "D:\SAS Class Sonam\Bharat.txt" firstobs =3 obs = 6;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 14 */
data ;
infile "D:\SAS Class Sonam\comma.txt" dlm=',' ;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 15 */
data ;
infile "D:\SAS Class Sonam\colon.txt" dlm=':,' ;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 16 */
data column (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @11 State $
            @14 Age
            @17 Height
            @20 Weight ;
run;

/* File Reading Program Number: 17 */
data column1 (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @17 Height
            @20 Weight ;
run;

/* File Reading Program Number: 18 */
data column2 (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @17 Height
            @20 Weight
            @11 State $
            @14 Age ;
run;

/* File Reading Program Number: 19 */
data column3 (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @17 Height
            @20 Weight
            @11 State $
            @14 Age
            @14 Ages;
run;

/* File Reading Program Number: 20 */
data column4 (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @17 Height
            @20 Weight
            @11 State $
            @14 Age
            @14 Age;
run;

/* File Reading Program Number: 21 */
options noreplace;
data good.column4 (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @17 Height
            @20 Weight
            @11 State $
            @14 Age
            @14 Agexx;
run;

/* File Reading Program Number: 22 */
data formatt (label=Format Input Style);
infile "D:\SAS Class Sonam\Separatef.txt" firstobs=2;
input       Name  $ Gender $ State $ Age HT Salary comma9.2;
run;
proc print data = formatt;run;

/* File Reading Program Number: 23 */
data Dollar (label=Format Input Style);
infile "D:\SAS Class Sonam\Separated.txt" firstobs=2 obs=5;
input       Name  $ Gender $ State $ Age HT Salary dollar10.2;
run;
proc print data = Dollar;run;

/* File Reading Program Number: 24 */
data Dollar (label=Named Input Style);
infile "D:\SAS Class Sonam\Separaten.txt" ;
input       Name=   $
            Gender= $
            State=  $
            Age=
            Height=
            Salary= dollar10.2;
run;
proc print data = Dollar;run;

/* File Reading Program Number: 25 */
data startend (label=Column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2 ;
input       Name $ 1-8
            Gender $ 9-10
            Height 17-19
            Weight 20-22
            State $ 11-12
            Age 14-15 ;
run;

/* File Reading Program Number: 26 */
data AtStartend (label=Column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2 ;
input       @1 Name $
            Gender $ 9-10
            Height 17-19
            Weight 20-22
            State $ 11-12
            Age 14-15 ;
run;

/* File Reading Program Number: 27 */
data MoreThan8(label=List Input Style);
infile "D:\SAS Class Sonam\Separatee.txt" firstobs=2 ;
input Name $ Gender $ State $ Height Weight  Age ;
run;
proc print data = MoreThan8 ;
run;

/* File Reading Program Number: 28 */
data MoreThan8(label=List Input Style);
infile "D:\SAS Class Sonam\Separateg.txt" firstobs=2;
input Name $18. Gender $ State $ Height Age Weight ;
run;
proc print data = MoreThan8 ;
run;

/* File Reading Program Number: 29 */
data MoreThan8(label=List Input Style);
infile "D:\SAS Class Sonam\Separatee.txt" firstobs=2;
input Name : $18. Gender $ State $ Height Age Weight ;
run;
proc print data = MoreThan8 ;
run;

/* File Reading Program Number: 30 */
data ;
infile "D:\SAS Class Sonam\csv.csv" dsd ;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 31 */
data ;
infile "D:\SAS Class Sonam\csv.csv" dsd lrecl=1000;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 32 */
data;
informat date_of_birth MMDDYY10. ;
input date_of_birth;
cards;
11/09/2010
02/02/1999
02/23/1956
01/01/1960
10/10/1960
12/12/1959
;
run;
proc print;run;

/* File Reading Program Number: 33 */
data;
informat date_of_birth MMDDYY10. ;
input date_of_birth;
format date_of_birth MMDDYY10. ;
cards;
11/09/2010
02/02/1999
02/23/1956
01/01/1960
10/10/1960
12/12/1959
;
run;
proc print;run;

/* File Reading Program Number: 34 */
data;
informat date_of_birth MMDDYY10. ;
input date_of_birth;
format date_of_birth Date9. ;
cards;
11/09/2010
02/02/1999
02/23/1956
01/01/1960
10/10/1960
12/12/1959
;
run;
proc print;run;

/* File Reading Program Number: 35 */
data;
informat date_of_birth MMDDYY10. ;
input date_of_birth;
format date_of_birth ddmmyy10. ;
cards;
11/09/2010
02/02/1999
02/23/1956
01/01/1960
10/10/1960
12/12/1959
;
run;
proc print;run;

/* File Reading Program Number: 36 */
data;
input date_of_birth : mmddyy10.;
dob1 = date_of_birth;
dob2 = date_of_birth;
dob3 = date_of_birth;
dob4 = date_of_birth;
format date_of_birth ddmmyy10b. ;
format dob1 ddmmyy10c. ;
format dob2 ddmmyy10d. ;
format dob3 ddmmyy10n. ;
format dob4 ddmmyy10p. ;

cards;
1/09/2010
2/02/1999
2/23/1956
1/01/1960
10/10/1960
12/12/1959
;
run;
proc print;run;

/* File Reading Program Number: 37 */
data ;
infile "D:\SAS Class Sonam\Bharat.txt" missover;
length Name $ 9 Gender $ 1 ;
input Name $ Gender $ State $ x1 - x3 ;
run;
proc print ;run;

/* File Reading Program Number: 38 */
data solved;
infile "D:\SAS Class Sonam\Bhism1.txt" ;
input Name : $10. Age;
run;
proc print ;run;

/* File Reading Program Number: 39 */
data solved;
filename fileref1  "D:\SAS Class Sonam\Bhism.txt" ;
infile fileref;
input Name : $10. Age;
run;
proc print ;run;

/* File Reading Program Number: 40 */
libname fileref  "D:\SAS Class Sonam\Bhism" ;
data fileref.Sales;
infile fileref;
input Name : $10. Age;
run;
proc print ;run;

/* File Reading Program Number: 41 */

data singleat;
input name $  gender $ @;
if gender ='m';
input age income ;
cards;
anuja f 22 20000
pooja f 24 28880
amit m 22 28000
ganesh m 29 30000
hira m 55 77800
rina f 32 77000
;
run;

/* File Reading Program Number: 42 */
data doubleat ;
input colors $ @@ ;
cards ;
w w w  r g b r g b r g b r g b r g b r g b w w
r g w w r g w w r g w w r g w w r g w w r g
;
run;

/* File Reading Program Number: 43 */

data singleat1;
input @'http:\\' website : $20.;
cards;
anuja f 22 http:\\www.yahoo.com 20000
pooja f 24 http:\\www.yah.com 28880
amit m 22 http:\\www.rax.com 28000
ganesh m 29 http:\\www.yoo.com 30000
hira m 55 http:\\www.hoo.com 77800
rina f 32 http:\\www.koo.com 77000
;
run;

No comments:

Post a Comment

Hot Topics