HPH 562 Data Management & Informatics: Lecture 2: Getting Your Data Into SAS
HPH 562 Data Management & Informatics: Lecture 2: Getting Your Data Into SAS
Sept 5, 2012
Organization Tips:
Create a folder for each class meeting Save all class documents in that folder
Lecture Lecture
Use this folder as your SAS library folder for that class.
Lecture Outline
Conceptual Model
Method 1: Importing DBMS Files Method 2: Table Entry Method 3: Internal Raw Data (Code) Method 4: External Raw Data
Method 1: Libname Method 2: Point and Click
Permanent
Character, Numeric
Lecture Code
*-----------------------------------* * HPH 562 * * Class 2 * *-----------------------------------*------------------------------------------* * Temporary Datasets * * Method 1:Importing data through the import wizard * * Method 2: Input data via SAS Table * * Method 3a: Internal Raw Data, List Input ; * * Method 3b: Internal Raw Data, Column Input; * * Method 4: External Raw Data; * * Permanent Databases * * Method 1: Libname * * Method 2: Point and Click * * Set Statement; * * Proc Contents; * *------------------------------------------------------------------------------*;
*Example of Creating New data examp1; Dataset; input ID BMI Gender $ VitDDefincient; datALinEs; 4687 31 F 0 7542 17 M 1 9637 18 F 1 ; run; *Example of Modifying a data examp2; Dataset; set examp1; If Gender = 1 or BMI>= 18.5 then FRAILTY=1; Else Frailty=0; run;
proc print data=examp1; *Example of Report; run; proc freq data=examp1; *Example of Utility table Gender*VitDDeficient; Function; run; proc means data=examp1; *Example of Analyzing Var BMI; Data; run;
SAS Datase t
Results of analysis
Bring data into SAS; Apply Inclusion Criteria; Create Outcome Frailty Variable; Create other predictor Variables;
PROC Proc step Statements; Frequency Tables; Odds Ratios (i.e. Logistic Regression);
Results of analysis
SAS Datase t
No
Example Code:
Data DatasetB; set DatasetA; Frail1=0; if BMI<=18.5 then Frail1 = 1;
Reads Data and Executes Statement Writes observation into dataset B Done. Modification s are now in dataset B
Frail2=0; if SLOWWALK=1 then Frail2 = 1; FRAILTY=0; if Frail1=1 or Frail2=1 then FRAILTY = 1; Run;
Bring data into SAS; Apply Inclusion Criteria; Create Outcome Frailty Variable; Create other predictor Variables;
PROC Proc step Statements; Frequency Tables; Odds Ratios (i.e. Logistic Regression);
Results of analysis
Temporary Datasets:
Stored
All
Import Wizard to bring in datasets stored excel or access format. data into SAS table it in your code
Method
Enter Type
Method Method
Pulling
1: Importing Database Management System (DBMS) files ID Heig Gende Intervention Result
Excel/Access
ht 46 752 67 71
r F M 0 0 Yes No
9673
969
62
69
F
M
1
1
Yes
Yes
2006
2006
PROC IMPORT OUT= WORK.datasetname DATAFILE= DRIVE:\Foldername\datasetname.xls" DBMS=EXCEL REPLACE; RANGE="Sheet1$"; GETNAMES=YES; MIXED=NO; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN;
2: Table Entry
Entering Data into SAS Table Steps (must be in the Explorer Window):
File New Table Enter Data Label Variables
You
46
752
67
71 62 69
F
M F M
0
0 1 1
Yes
No Yes Yes
2005
2005 2005 2005
1. 2. 3.
input statement Define the variables, character$ or numeric Specify the location of the raw data (in this case, your location is datalines, meaning youre inputting the raw data
data example2; input ID Height Gender $ Intervention Result $ Year; datalines; 46 67 F 0 Yes 2005 752 71 M 0 No 2005 9673 62 F 1 Yes 2005 969 69 M 1 Yes 2005 ; run;
1. 2. 3.
input statement Define the variables, character$ or numeric Specify the location of the raw data (in this case, your location is datalines, meaning youre inputting the raw data
1 2 2 1-------9-------7-------5---9--46 67 F 0 Yes 2004 752 71 M 0 No 2004 9673 62 F 1 Yes 2004 969 69 M 1 Yes 2004 ; run;
1.
2. 3.
Specify the location of the raw data (in this case, your location is a browser location); input statement Define the variables, character$ or numeric
969
data example4; infile "G:\HPH 562\Class 2 Final\Example4\ex4.txt"; input ID Height Gender $ Intervention Result $ Year @@; run;
Permanent Datasets:
Datasets
have two names Stored in a folder you create within SAS Libraries Purposes
Store
Class2a
Name of library
While the Explorer window is highlighted, click File/New Fill in required fields (name of folder, location of folder)
Tip: If youre returning to the same code every time, its easier to form your library through the Libname statement.
J:\
2
J:\Class2a
CLASS2A
Hmwk2
Class2a
Now, in SAS, create a permanent library referencing the folder where your database is saved.
Libname PermFoldername BrowserAddress"; run; data nameoftemporarydatabase; set Permfoldername.databasename; run; Location of Library where my data PERMANENT is stored
Libname BASIL"G:\HPH 562\DRAFT\Datasets\NAMCSIII "; run; Name of new Temporary Database data Slide20; set BASIL.namcsedit; run; Name of my Permanent database
Code:
data PermFolderName.Permdatabase; set tempdatabase; run;
Example
data BASIL.SLIDE; set slide21; run;
MUST CREATE A LIBRARY WHERE THE PERMANENT SAS DATABASE IS STORED in order to access database
The only way to look at an Excel database is through the Excel program. Same thing with SAS. The only way to look at a SAS database in through the SAS program. The difference between the two is the SAS program does not automatically open when you try to open a SAS database. You must physically open SAS first, and create a permanent library where that database is stored. Then, you may look at the data.
Excel/Access Databases:
Proc Contents
of Observations Variables
Name
Type Length