Home Work 4



Home Work 6

Due by 12:00 noon, 2/28 (Sunday)

Note: Make sure you run the code in SAS. Let me know for any questions.

1. Run the following program creates two dataset group1 and group2.

data group1;

input team $1-7 win loss;

cards;

Detroit 30 18

Chicago 28 23

Atlanta 19 30

;

run;

data group2;

input team $1-11 win loss;

cards;

Sacramento 21 26

San Antonio 33 17

;

run;

a) Use proc contents to check both data’s variable attributes.

b) Write a sas program to combine the two data vertically, output data is: ALL

c) Use proc contents to check data ALL’s variable attributes. What is the length for variable team? Use proc print to review the data.

d) How many observations are there in the output data ALL.

*** Solutions;

*** a) ;

proc contents data=group1; run;

proc contents data=group2; run;

*** b) Method 1;

data ALL;

length team $11;

set group1 group2;

run;

*** b) Method 2;

data ALL;

set group2 group1;

run;

*** c) ;

proc contents data=ALL; run;

*** Length for team is $11;

*** d) ;

Data ALL has 5 observations.;

2. Run the following program, create two SAS datasets: card_data and card_data2. The two data are exactly the same, each has 160,880 rows.

libname dd '/courses/ddbf9765ba27fe300';

data card_data;

set dd.simulated_card_data;

run;

data card_data;

set card_data card_data card_data card_data card_data

card_data card_data card_data card_data card_data

card_data card_data card_data card_data card_data

card_data card_data card_data card_data card_data

card_data card_data card_data card_data card_data

card_data card_data card_data card_data card_data

card_data card_data card_data card_data card_data

card_data card_data card_data card_data card_data;

run;

data card_data2;

set card_data;

run;

a) Write a SAS data step, vertically concatenate card_data and dd.one_row.

Output data: card_data1

data card_data1;

set card_data dd.one_row;

run;

b) Write a SAS proc append step, vertically concatenate card_data2 and dd.one_row.

Output data: card_data2

proc append base = card_data2

data = dd.one_row;

run;

c) Look into the SAS Log, Fill in the following Time column.

d) Which method is more efficient? Proc Append is more efficient.

|data/set method |Time |  |Proc Append Method |Time |

|================= |=========== |  |=================== |==========  |

|real time | 0.05 sec |  |real time | 0.00 sec |

|user cpu time | 0.00 sec |  |user cpu time | 0.00 sec |

|system cpu time | 0.06 sec |  |system cpu time | 0.00 sec |

3. In the directory /courses/ddbf9765ba27fe300, there are two sas datasets: BALANCE and SALE.

A) Write a sas program to merge the two data horizontally into work.final_1 by ID. Only observations that both data have contribution will be in the output.

B) Write a sas program to merge the two data into work.final_2 by ID. Only observations that

BALANCE data have contribution will be in the output.

Because both input data have variable TYPE and ORDER, which data’s value will be in the output data according to your code?

A)

libname cc 'c:\sas_class\classdata';

proc sort data=cc.balance out=balance;

by ID;

run;

proc sort data=cc.sale out=sale;

by ID;

run;

data work.final_1;

merge balance(in=aa) sale(in=bb);

by ID;

if aa and bb;

run;

B)

data work.final_2;

merge balance(in=aa) sale(in=bb);

by ID;

if aa;

run;

Sale data’s TYPE and ORDER values will be in the output data.

For rows that Sale data has no contribution, Balance data’s value will remain in the output data.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download