There are some methods to create datasets in SAS.
1.Reading files with Import Wizard : simply by selecting the type of file and location and
wherther you want to consider first row as variable name or not you can simply create a dataset.
2. Creating Dataset from RAW file: we can create the dataset from raw file.
with infile statement we can read any raw file even if the delimiter is different.
We can simply use the DLM infile option .
for example:
data t
infile 'C:/Document/Text.txt' dlm=' ' and other infile options ;
input..............
run;
3. Creating Dataset from Proc Import.
PROC IMPORT DATAFILE = ’filename’ OUT = data-set
DBMS = DLM REPLACE;
GETNAMES = NO;
DELIMITER = ’delimiter-character’;
RUN;
Example The following example uses data about Jerry’s Coffee Shop where Jerry employs local
bands to attract customers. Jerry keeps records of the number of customers present throughout the
evening for each band. The data are the band name, followed by the gig date, and the number of
customers present at 8 p.m., 9 p.m., 10 p.m., and 11 p.m. Notice that one of the bands, “Stop, Drop,
and Rock-N-Roll,” has commas in the name of the band. When a data value contains the delimiter,
then the value must be enclosed in quotation marks.
Band Name,Gig Date,Eight PM,Nine PM,Ten PM,Eleven PM
Lupine Lights,12/3/2003,45,63,70,
Awesome Octaves,12/15/2003,17,28,44,12
”Stop, Drop, and Rock-N-Roll”,1/5/2004,34,62,77,91
The Silveyville Jazz Quartet,1/18/2004,38,30,42,43
Catalina Converts,1/31/2004,56,,65,34
Here is the program that will read this data file and print out the SAS data set after importing:
PROC IMPORT DATAFILE ='c:\MyRawData\Bands.csv' OUT = music REPLACE;
PROC PRINT DATA = music;
TITLE 'Customers at Each Gig';
RUN;
Here are the results of the PROC PRINT. Notice that GigDate is a readable date. This is because
IMPORT automatically assigns informats and formats to some forms of dates. (See section 4.5 for a
discussion of formats.)
Customers at Each Gig 1
Obs Band_Name Gig_Date Eight_PM Nine_PM Ten_PM Eleven_PM
1 Lupine Lights 12/03/2003 45 63 70 .
2 Awesome Octaves 1 2/15/2003 17 28 44 12
3 Stop, Drop, and Rock-N-Roll 01/05/2004 34 62 77 91
4 The Silveyville Jazz Quartet 01/18/2004 38 30 42 43
5 Catalina Converts 01/31/2004 56 . 65 34