Thursday, March 13, 2008

Read PC database files

To read PC database files, you use the IMPORT procedure. PROC IMPORT reads the input file and writes the data to a SAS data set, with the SAS variables defined based on the input records.

/*************************************/
/* import the Excel file */
/*************************************/
proc import datafile="c:\myfiles\Accounts.xls"
out=sasuser.accounts;
sheet="Prices";
getnames=no;
run;

/*************************************/
/* print part of the new data set */
/*************************************/
proc print data=sasuser.accounts(obs=10);
run;

/*************************************/
/* import the Access file */
/*************************************/
proc import table="customers"
out=sasuser.cust dbms=access;
uid="userid";
pwd="mypassword";
database="c:\myfiles\east.mdb";
wgdb="c:\winnt\system32\security.mdb";
run;
/*************************************/
/* print part of the new data set */
/*************************************/
proc print data=sasuser.cust(obs=5);
run;


/*************************************/
/* create variables with INPUT */
/*************************************/
data diabetes;
input ID $ Sex $ Age Height Weight
Pulse FastGlucose PostGlucose;
datalines;
2304 F 16 61 102 100 568 625
1128 M 43 71 218 76 156 208
4425 F 48 66 162 80 244 322
1387 F 57 64 142 70 177 206
9012 F 39 63 157 68 257 318
6312 M 52 72 240 77 362 413
;
run;

/*You can use keyword datalines; or cards; */

No comments: