Anda di halaman 1dari 3

/*ways to read data into SAS from different data sources

1: DATALINES |instream|*/
data dataline;
infile datalines;
input id name$ age sex$ location$ salary;
datalines;
101 abc 21 m hyd 10000
102 def 22 f hyd 10000
103 ghi 23 m che 20000
104 jkl 24 f che 20000
105 mno 25 m ban 30000
106 pqr 26 f ban 30000
;
run;
/* 2: EXTERNAL FILES
(A) NOTEPAD.
two ways to read notepad data
i) data method.
raw data without column names*/
data notepad1;
infile 'D:\sample text\sample1.txt';
input id name$ sex$ age salary location$;
run;
/*raw data with column names*/
data notepad2;
infile 'D:\sample text\sample1-with-variable-names.txt' firstobs=2;
input id name$ sex$ age salary location$;
run;
/* ii) proc import method.
raw data without column names*/
proc import datafile= 'D:\sample text\sample1.txt'
out=work.notepad3
dbms=tab;
getnames=no;
delimiter=' ';
run;
/*raw data with column names*/
proc import datafile= 'D:\sample text\sample1-with-variable-names.txt'
out=work.notepad4
dbms=tab;
delimiter=' ';
run;
/* (B) CSV
two ways to read notepad data
a)data method.
b)proc import method.
data method*/
data csv1;
infile 'D:\STANSYS MATERIAL\1. SOURCE DATA\CSV\DATA.csv'
delimiter=','

firstobs=2
missover;
input State$ Pcode$ area$ month stock sale;
run;
/*proc import method */
proc import datafile='D:\STANSYS MATERIAL\1. SOURCE DATA\CSV\DATA.csv'
out=work.csv2
dbms=csv;
run;
proc import datafile='D:\STANSYS MATERIAL\1. SOURCE DATA\CSV\DATA.csv'
out=work.csv2a
dbms=csv
replace;
getnames=yes;
run;
/* (C) EXCEL
proc import method without column names */
proc import datafile='D:\STANSYS MATERIAL\1. SOURCE DATA\EXCEL\Emp.xls'
out=work.excel1
dbms=xls
replace;
getnames=no;
run;
/*proc import method with column names */
proc import datafile='D:\STANSYS MATERIAL\1. SOURCE DATA\EXCEL\Emp-with-columnnames.xls'
out=work.excel2
dbms=excelcs;
run;
/*specifying the sheets*/
proc import datafile='D:\STANSYS MATERIAL\1. SOURCE DATA\EXCEL\aa.xls'
out=work.excel3
dbms=excelcs;
sheet=sheet2;
run;
/* (D) MS-ACCESS
observe, there is small change, table and database is included*/
proc import table=Employ_Promtion_Master
out=work.access1
dbms=accesscs
replace;
database='D:\STANSYS MATERIAL\1. SOURCE DATA\MSACCESS\Assign3.mdb';
run;
/* 3: EXISTING SAS DATASETS
(A) internal sas datasets {where datasets are present in sas libraries only}*/
data ds1;
set sashelp.class;
run;
data ds2 (drop=height weight);
set sashelp.class;

run;
/*(B) external sas datasts {datasets only but available at different
location/server}
if we want to import only single sas dataset*/
data ds3;
set 'D:\STANSYS MATERIAL\1. SOURCE DATA\SAS DATASETS\AIRLINE\delay.sas7bdat';
run;
/*if we wanna import entire library to our sas library*/
libname naresh 'D:\STANSYS MATERIAL\1. SOURCE DATA\SAS DATASETS\SHOES';
/* 4: DATABASES
(A) oracle creating two tables at single time*/
proc sql;
connect to oracle (user=scott password=tiger);
create table work.oracle1 as select * from connection to oracle (select * from emp);
create table work.oracle2 as select * from connection to oracle (select * from
salgrade);
disconnect from oracle;
quit;

Anda mungkin juga menyukai