SAS Programming

 

Class meeting 04/02/2012

 

Note: This lecture is focused on raw data input in SAS data step. The exercises are due on Wednesday, 4/11/2012. Hard copy is required.

 

Try to access Base SAS help and Documentation at below.

 

 

 

  1. Go through chapter 1-7 by running all the programs. Understand the functions of the statements in the program. If you have difficulties to find the right help information, you can access \\TechShare\Coba\d\ISQS3358\Texts\data-PROG1\. All SAS file with BUG0*.sas are the same copied from the above help documents (Chapter 3-7)

 

  1. The following are the exercises for the class:

 

Problem 1:

 

See the following code:

 

/*------------------------------------*/

data bodyfat;

input sex $ fatpct @@;

cards;

m 13.3 f 22

m 22 f 23.2

m 16 m 12

;

run;

/*------------------------------------*/

 

Do you know how double trailing @@ works? What is the difference of it from single trailing @? Check pp4-77 to 4-79 in PROG2.pdf (not PROG1), which is available in the same path as you access PROG1. You feel free to read more about the context in the same chapter.

 

Create a simple dataset and write a SAS code to test the difference between @ and @@ in INPUT.

 

Problem 2:

 

There is a database log file DATA.LOG.txt in \\TechShare\Coba\d\ISQS3358\OtherDatasets\Log-data\.

Complete the INPUT statement in the following code to input the data to library WORK.

 

/*------------------------------------*/

data dblog;

infile 'DATA.LOG.txt';

/* create the INPUT statement here */

 

RUN;

proc print data=dblog;

run;

/*------------------------------------*/

 

Problem 3:

 

Study the following code

 

/*------------------------------------*/

data club0;

INFILE "C:\Lin\Shared\ISQS6339\LWEGQR4\Afs_orders.txt"

DELIMITER=','

MISSOVER

DSD

FIRSTOBS=2

 

;

 

INPUT

ORDER_NUMBER

CUSTOMER_ID $

DATE_ORDERED

DATE_SHIPPED

ORDER_TYPE $

CARRIER $

PRODUCT_CODE $ QUANTITY MONTH;

INFORMAT

DATE_ORDERED MMDDYY10.

DATE_SHIPPED MMDDYY10.

;

FORMAT

DATE_ORDERED MMDDYY10.

DATE_SHIPPED MMDDYY10.

;

;

run;

proc print data=club0;

title 'Weight Club Members';

run;

/*---------------------------*/

 

Write a SAS code to input and print the following comma delimited data:

 

Tom,35,M

Jack,28,M

Cathy,29,F

 

If the data is tab delimited how could you solve the problem?

 

Problem 4:

 

Check dataset COMMREX.COM-ACCESS_LOG-9711.TXT in

\\TechShare\Coba\d\ISQS3358\OtherDatasets\weblog\. If you have problem to see it clearly, you may use EXCEL to open it. The following code convert the file to a SAS dataset:

 

/*---------------------------*/

data weblog;

infile "COMMREX.COM-ACCESS_LOG-9711.TXT" DLM=' ';

input user :$40. @ '[' date date11. @ ':' time time8. @ 'GET' page :$40.;

 

RUN;

 

proc print data=weblog;

var user date time page;

/*---------------------------*/

run;

 

Questions:

1)      Which parameter in the INFILE statement is configured for converting the delimited file? If you have different delimiters how should the parameter be changed?

2)      What is the purpose of @ '[' and @ ':'?

3)      What is the purpose of : in user :$40. and page :$40.?

 

The above exercises are due on Wednesday, 4/11/2012 before the class.