This video series is intended to help you learn how to program using SAS for your statistical needs. Lesson 3 introduces the concept of permanent or external data sets and how to import them into SAS. I provide basic methods of importing permanent data sets using the INFILE ;statement and the IMPORT procedure (PROC ;IMPORT) for non-SAS based data files. I also discuss libraries and the LIBNAME ;statement to import SAS data directly using the SET statement. Finally, I show how one can save a SAS data set from the data step using LIBNAMEs in the DATA step.
1. The LIBNAME statement is used to point SAS towards a specific folder on your computer.
2. The INFILE statement “reads” data into SAS if it is of a certain format (usually comma, space, or tab delimited).
3. PROC IMPORT – imports data of any of several different file formats into SAS.
4. The SET statement imports data from a library into SAS at the DATA STEP.
5. The library name in a data step’s data name “writes” data from SAS into your library folder using SAS’s own file format system.
input x y z;
1 2 3
7 8 9
proc contents data=main;
proc print data=main;
/* TEMPLATED CODE: .txt file type, with or without delimiters */
data [appropriate data set name here]; infile ;”[your file location here, including .txt extension]” LRECL=[a logical length of your data to emcompass ;ENTIRE data] DLM=’,’;
[variable names here]
infile “C:\My SAS Files\main.txt”;
input x y z;
proc print data=infile_main;
/* TEMPLATED CODE: Microsoft Excel (.xls) file type */
proc import out=[your data set name here]
datafile='[your file location here, including .xls extension]’
*Optional statements are below; sheet='[specify sheet to obtain]’; getnames=[yes/no – first row = variable names]; mixed=[yes/no – refers to data types, if num AND char varibles, use yes]; usedate=[yes/no – read date formatted data as date formatted SAS data]; scantime=[yes/no – read in time formatted data as long as variable is not date format];
proc import out=imported_excel
datafile=’C:\My SAS Files\main.xls’
*Optional statements are below; sheet=’Sheet1′; getnames=yes;
proc print data=imported_excel;
libname home “C:\My SAS Files\”;
data sas_format; set home.main;
data home.sas_format; set infile_main;
“Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for “fair use” for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use.”
Anayansi Gamboa has an extensive background in clinical data management as well as experience with different EDC systems including Oracle InForm, InForm Architect, Central Designer, CIS, Clintrial, Medidata Rave, Central Coding, OpenClinica Open Source and Oracle Clinical.