stat 440 lab exercises 14
stat 440 lab exercises 14
1
Statistics 440: Lab Exercises 14
Select Browse… to specify a workbook file to import from the Open window. After you
select the pathname, select Open to complete your selections and return to the Connect to MS
Excel window.
4. Select OK. The Import Wizard – Select Table window opens:
2
Statistics 440: Lab Exercises 14
5. Select Sheet_1, the name of the worksheet (or named range) to be imported.
You can select Options… to change default import settings through the SAS Import:
Spreadsheet Options window.
6. Select Next > to open the Import Wizard – Select library and member window, where you
specify the storage location for the imported file.
7. In the Library box on the left, leave the library as WORK. In the Member box on the right, type
inventory.
You can also select the down arrow in the Library box and select a different library. You can
select the down arrow in the Member box to select an existing data set. If you select an
existing data set, you will be asked later to verify that you want to replace it.
3
Statistics 440: Lab Exercises 14
8. Select Next > to move to the next window or Finish to create the SAS data set from the
Excel spreadsheet.
If you select Finish and you select the name of an existing SAS data set for the name of your
new SAS data set (in the Import Wizard – Select library and member window), you are
prompted to determine whether or not you want to replace the existing data set. Select OK or
Cancel.
If you select Next >, you are taken to the Import Wizard – Create SAS Statements window.
9. Select Browse… to specify a location from the Save As window. After you select the
pathname, select Save to complete your selections and return to the Import Wizard – Create
SAS Statements window.
If the file already exists, you are prompted to replace the existing file, append to the existing
file, or cancel the save.
10. Select Finish.
11. Check the log to see that the SAS data set is successfully created.
NOTE: WORK.INVENTORY was successfully created.
12. Go to the Program Editor window and write SAS code to print the data set.
proc print data=work.inventory;
run;
4
Statistics 440: Lab Exercises 14
13. Go to the Program Editor window and open the SAS code created by the Import Wizard.
PROC IMPORT OUT=WORK. inventory
DATAFILE="D:\netid\inventory.xls"
DBMS=EXCEL REPLACE;
SHEET="Sheet_1";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
The default is MIXED=NO, which means that numeric data will be imported as missing values in
a character column. The MIXED= option is available only when reading Excel data.
When using the Import Wizard, the MIXED=YES option can be set by selecting Convert
numeric values to characters in a mixed types column in the SAS Import: Spreadsheet Options
window.
5
Statistics 440: Lab Exercises 14
PROC
PROCIMPORT
IMPORTOUT=SAS-data-set
OUT=SAS-data-set
DATAFILE='external-file-name‘
DATAFILE='external-file-name‘
<< DBMS=file-type
DBMS=file-type >> <REPLACE>;
<REPLACE>;
RUN;
RUN;
REPLACE
overwrites an existing SAS data set.
106
If external-file-name contains a valid extension so that PROC IMPORT can recognize the type of
data, you may omit the DBMS= option.
6
Statistics 440: Lab Exercises 14
Part II: Writing Data to an External File with the Export Wizard
Use the Export Wizard to import the SAS data set customers into MS ACESS.
1. From the Start menu, open Microsoft Office Access. Create a new MS Access database called
“officesupply.accdb” and save it in ‘D:\netid’. Close the database. You cannot export tables
into an Access database from SAS while it is open.
2. Go back to your SAS session. Select File Export Data….
3. In the Select library and member window, specify the library st and member (SAS data set)
customers. Select Next >.
4. From the list box, select Microsoft Access 200x Database. Select Next >.
7
Statistics 440: Lab Exercises 14
Select Browse… to specify a database file to export to from the Open window. Select the
pathname ‘D:\netid\officesupply.mdb’.
6. Select OK. The Export Wizard – Select Table window opens:
8
Statistics 440: Lab Exercises 14
9
Statistics 440: Lab Exercises 14
9. Select Browse… to specify a location from the Save As window (use D:\netid\export.sas).
After you select the pathname, select Save to complete your selections and return to the
Export Wizard – Create SAS Statements window.
If the file already exists, you are prompted to replace the existing file, append to the existing
file, or cancel the save.
10. Select Finish.
11. Check the log to see that the SAS data set is successfully created.
NOTE: ’customers’ was successfully created.
12. Go to the Program Editor window and open the SAS code created by the Export Wizard.
PROC EXPORT DATA= ST.CUSTOMERS
OUTTABLE= "customers"
DBMS=ACCESS REPLACE;
DATABASE="D:\netid\officesupply.mdb";
RUN;
13. Edit the SAS code created by the Export Wizard to export the SAS data sets inventory,
invoice, manufacturers, and products.
10
Statistics 440: Lab Exercises 14
3. Creating Relationships
a. To open the Relationships window, choose Database Tools tab and click the Relationship
button on toolbar. Since no relationships have been defined, the Show Table
window opens.
11
Statistics 440: Lab Exercises 14
b. Select all five tables then click Add. The Relationships window appears.
12
Statistics 440: Lab Exercises 14
c. To relate the customers table to the invoice table by CUSTNUM, drag the CUSTNUM
field from customers to the CUSTNUM field in the invoice table. The Edit
Relationship window opens.
d. Click Create. A relationship line should now be drawn between the two tables.
e. Create additional relationships between
• invoice and products on PRODNUM
• products and inventory on PRODNUM
• products and manufacturers on MANUNUM
13
Statistics 440: Lab Exercises 14
a. Select the Create tab, click Queries, then click the Query Wizard icon from the
toolbar. Select Simple Query Wizard from the New Query window.
c. Click Next.
14
Statistics 440: Lab Exercises 14
15
Statistics 440: Lab Exercises 14
f. Switch to Design view (make sure the Home tab is selected) by clicking the View icon,
then select Design View.
16
Statistics 440: Lab Exercises 14
b. In the editor window that appears, modify the SQL statement so that all the rows in the
invoice table are returned by the query.
d.
17
Statistics 440: Lab Exercises 14
e. Select the Datasheet view to preview the rows that will be returned by the query.
g. From the toolbar, select the Make Table Query icon . In the Make Table window,
name the new table software_prod then click OK.
h. Save the query by clicking the Save button on the toolbar. Name the query “make
software_prod”.
-The End-
Portions Copyright 2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.
Reproduced with permission of SAS Institute Inc., Cary, NC, USA. SAS Institute Inc. makes no
warranties with respect to these materials and disclaims all liabilities thereof.
18