3.reading importing raw data into sas
TRANSCRIPT
8/19/2019 3.Reading Importing Raw Data Into Sas
http://slidepdf.com/reader/full/3reading-importing-raw-data-into-sas 1/5
Home » SAS » SAS For Beginners » Reading / Importing Raw Data into SAS
READING / IMPORTING RAW DATA INTO SAS
Deepanshu Bhalla 3 Comments SAS, SAS For Beginners
I. Entering Data Directly in SAS Program -
DATALINES You can enter our lines o! data directl in our SAS program " usinga DATALINESstatement#
$et%s start out " clari!ing the main &ewords associated with the!ollowing program# 'he &ewords are (1. DATA - 'he DA'A step alwas "egins with a DATA statement# 'hepurpose o! the DA'A statement is to tell SAS that ou are creating a newdata set i#e# outdata.2. INPUT - 'o de)ne the *aria"les used in data set#3. Dollar sign !" - 'o identi! *aria"le as character##. DATALINES + 'o indicate that lines !ollowing DA'A$I-S statement areal data#$. P%&' P%INT + 'o print out the contents o! data set in output window#(. %UN + 'he DA'A step ends with a R. statement#
DA'A outdata
I0.' age gender 1 dept o"s2 o"s o"s3
DA'A$I-S
2 F 3 24 5 6
2 7 2 28 9 4
3 7 6 6 2: :
3 F 28 3 ;
F 2 26 3 2
7 9 2 3 8
3 7 2 ; 2 4
2 F 2 4 4 26
3 F 2
2 7 9 : 9
3 7 6 2 ; 2;
2 7 6 4 8 9
F 9 2: 24 :
8/19/2019 3.Reading Importing Raw Data Into Sas
http://slidepdf.com/reader/full/3reading-importing-raw-data-into-sas 2/5
3 F 6 2 9 4
3 F 3 8 8 9
3 7 3 4 2 9
F 2 2 23
F 9 : 9
proc print
run
II. )et E*ternal +ile into SAS - IN+ILEIN+ILE statement - 'o speci! path where data )le is sa*ed#DSD - 'o change the de!ault delimiter !rom a "lan& to comma#DA'A outdatain)le %c(<deepanshu<sampledata#cs*% dsdI0.' age gender 1 dept o"s2 o"s o"s3
run
,o to andle an e*ternal /le 0.sing a +ILENAE statement to handle an e=ternal )le#
+ILENAE samle c04deeansu4samledata.cs5 6
DA'A outdatain)le samle dsdI0.' age gender 1 dept o"s2 o"s o"s3run
%eading Delimited Data 'he de!ault delimiter is "lan&# I! ou ha*e a data )le with other delimiterssuch as comma or ta" ou need to de)ne the delimiter "e!ore de)ning the*aria"les using IN+ILEand DL 7 options#
Synta* 0 In)le %)le+description% dlm>%,%
DA'A outdata
I0.' age gender 1 dept o"s2 o"s o"s DA'A$I-S2 F 3 24 5 6
8/19/2019 3.Reading Importing Raw Data Into Sas
http://slidepdf.com/reader/full/3reading-importing-raw-data-into-sas 3/5
For ta" delimiter, the snta= would "e in/le /le-descritiondlm789*For colon delimiter, the snta= would "e in/le /le-descrition dlm70
DA'A outdata
IFI$- Datalines dlm >?,? I0.' age gender 1 dept o"s2 o"s o"s3
Datalines2,F,3,24,5,62,7,2,28,9,43,7,6,6,2:,:3,F,,28,3,;,F,2,26,3,2proc printrun
'on5erting oter :ormat /les into SAS datasets1. Imorting an E*cel +ile into SAS 'he main &ewords used in the !ollowing program are (
1. &UT - 'o speci! name o! a data set that SAS creates# In the program"elow, outdatais the data set sa*ed in wor& li"rar @temporar li"rar2. D;S - 'o speci! the tpe o! data to import#3. %EPLA'E - 'o o*erwrite an e=isting SAS data set##. S,EET - 'o import a speci)c sheet !rom an e=cel wor&"oo&$. )ETNAES - 'o include *aria"le names !rom the )rst row o! data#0RC I70R' DA'AFI$-> ?c(<deepanshu<sampledata#=ls?.'> outdataDB7S>=lsR-0$AC-
SH--'>?Sheet2?-'A7-S>Y-SR.
2. Imorting a Ta<-Delimited +ile into SAS
0RC I70R' DA'AFI$-> ?c(<deepanshu<sampledata#t=t?.'> outdata
8/19/2019 3.Reading Importing Raw Data Into Sas
http://slidepdf.com/reader/full/3reading-importing-raw-data-into-sas 4/5
DB7S>dlmR-0$AC-delimiter>%:8%=-'A7-S>Y-SR.
3. Imorting a 'omma-Delimited +ileP%&' IP&%T DATA+ILE7=c04deeansu4samledata.t*t=
&UT7 outdataD;S7dlm%EPLA'E6delimiter7>6)ETNAES7?ES6%UN6
#. Imorting a Sace-Delimited +ile
0RC I70R' DA'AFI$-> ?c(<deepanshu<sampledata#t=t?.'> outdataDB7S>dlmR-0$AC-delimiter>%:%=-'A7-S>Y-SR.
$. Imorting a /le containing multiledelimiter
8/19/2019 3.Reading Importing Raw Data Into Sas
http://slidepdf.com/reader/full/3reading-importing-raw-data-into-sas 5/5
I! two or more delimiters, such as comma and ta"s, uote them!ollowing delimiter 7option0RC I70R' DA'AFI$-> ?c(<deepanshu<sampledata#t=t?.'> outdata
DB7S>dlmR-0$AC-delimiter>%,%:8%= %-'A7-S>Y-SR.