Home Work 3

Due by 11:00 pm, 1/30 (Saturday)

Note: Please read through the class document. The home work may be a little harder this time. Start early so you can receive it early before the midterm.

1.Read and run the following sas code. Then write a sas code:

Input data: date_conversion

Output data: date_conversion2

Create two new variables:

Variable 1: cdaten, its value is the sas date number of variable cdate.

Variable 2: ndaten, its value is the sas date number of variable ndate.

Finally, format both new variables to date9. format.

Hint: Use Input() function. See example in the class document.

data date_conversion;

cdate = '01DEC2012';

ndate = '20121201';

run;

2.Read the following program (DO NOT RUN IT), then fill in the blanks bellow the program

for each variable's value in the output data.

data math;

input M1 M2 M3 M4;

datalines;

5 . 10 25

;

run;

data math2;

set math;

M_all = M1 + M2 + M3 + M4;

sum_M1 = sum(M1, M2, M3, M4);

sum_M2 = sum(of M1 - M4);

sum_M3 = sum(M1 - M4); run;

M_all = ____ sum_M1 = ____ sum_M2 = ____ sum_M3 = ____

3.Review the following program, fill in the blanks bellow the

program.DO NOT RUN THE PROGRAM.

/* 1 2 3 4 5 6

123456789012345678901234567890123456789012345678901234567890 */

data a;

c='CARDIOVASCULAR DIAGNOSTICS TAS ANALYZER';

c1=index(c, 'DIAGNOSTICS');

if index(c, 'DIAGNOSTICS')>0 then output; * often used for data selection;

c2=index(c, 'ZZZ');

c3=substr(c,28);

c4=substr(c,28,3);

c5=scan(c, 1);

c6=scan(c,3);

c7=find(c, ‘tas’, ‘i’);

c8=scan(c, -2);

c9=find(c, 'DIAG', -200);

d=’3.14, 2.718, 6.021’;

d1=scan(d,2,’,’);

nmth=intck('month', '01APR2008'd, '01OCT2008'd);

futurem = intnx('month', '01APR2008'd, 5);

run;

In the output dataset, c1 = ____ c2 = ____ c3 =______

C4 = ______c5 = ______c6 = ______

C7 = ______C8 = ______C9 = ______d1 = ______

Nmth = ______future = ______

4.Run the following sas code, and generate the sas dataset citiday (this is a random sample of sashelp.citiday, and some modifications).

Then write a sas program to only select the observations with the year of variable DATE equal 1990, and values for variable CODE contains a letter ‘B’ or ‘b’. Make the output dataset name as: citi_1990_B.

DATA citiday;

input obs @7 DATE date9. SNYDJCM SNYSECM RAND CODE $;

FORMAT DATE DATE9.;

cards;

1 13MAR1990 1000.14 185.250 0.000066 A

2 18JUL1990 1053.54 198.830 0.004055 A

3 06APR1989 875.67 166.020 0.006425 B

4 07JUN1989 955.66 182.340 0.007558 b

5 22SEP1988 782.43 152.080 0.007750 A

6 20MAR1991 1016.88 201.310 0.008089 D

7 07FEB1989 896.15 168.020 0.008591 EZXCV

8 01MAY1991 1049.15 208.030 0.008781 CLXCF

9 23DEC1991 1097.89 218.130 0.009431 CSDFSL

10 29MAR1991 . . 0.011231 DLQWE

11 09AUG1989 1065.94 193.200 0.011660 FZXC

12 19JUN1991 1053.52 205.780 0.012173 SDSSDL

13 28MAR1991 1034.97 205.300 0.012185 SDFLEF

14 14OCT1991 1087.87 212.570 0.012366 DELZXC

15 26SEP1989 1062.77 191.470 0.013321 CQE

16 11SEP1990 908.95 176.390 0.013870 BQWE

17 11DEC1991 1040.27 208.530 0.014056 BLADFG

18 15JAN1990 996.40 186.710 0.014558 SASD

19 06AUG1991 1079.33 213.710 0.016311 SADLAS

20 30AUG1990 897.90 175.230 0.017318 DLASD

21 02JAN1989 . . 0.019580 SASDF

22 07MAR1989 872.05 165.280 0.020474 DAD

23 18JUL1989 990.93 184.910 0.021558 AO

24 15FEB1990 976.43 184.700 0.021742 b

25 16AUG1988 755.94 147.490 0.023900 AAD

26 28SEP1989 1073.37 193.550 0.024501 CADF

27 16DEC1991 1063.08 212.080 0.024666 VSDF

28 26JAN1988 714.05 140.260 0.025723 XAD

29 01SEP1988 752.01 146.680 0.025802 ZASDF

30 20APR1990 997.80 184.060 0.026594 Mb

31 21FEB1991 1031.89 199.270 0.027155 EM

32 23APR1991 1045.31 208.680 0.028099 SLASDFL

33 04JAN1991 905.60 175.950 0.028491 DADF

34 16JAN1990 1007.56 188.370 0.029244 ALFA

35 08NOV1989 1002.96 187.480 0.029866 VSFG

36 21NOV1990 885.33 172.730 0.030451 CSDFG

37 27FEB1989 862.93 161.950 0.031587 BSDF

38 24MAR1988 764.35 149.000 0.031632 CRDFGH

39 27MAR1990 1020.85 187.400 0.036401 XAD

40 19FEB1991 1040.26 201.400 0.037930 DDFLA

41 05FEB1990 973.52 183.350 0.037951 CSD

42 21DEC1989 1012.46 190.500 0.038834 ASDF

;

RUN;

5. Run the following program, create a SAS dataset Interest. Then write another data step, use Interest as input dataset, do the followings in one data step. Make the output dataset name as Interest2. (Be aware that character variable’s value is case sensitive).

a)Create variables FNAME and LNAME and make their value equal the first name and last name respectively.

b)Create a numeric variable TRA_DIN, if the interest has travel or dining, TRA_DIN=1, otherwise, TRA_DIN=0.

c)Create another variable First_int, its value is the first interest in the interest list.

d)Create another variable Last_int, its value is the last interest in the interest list.

data Interest;

infile cards truncover;

input name $1-18 interest $20-52;

cards;

John Smith music, move, reading, Dining

Jay Wang shopping, gardening, Travel

Mike Bown basketball, tennis, social

Karen Odonnard boating, travel, hiking, dining

Scot K Norton Hunting, hiking, skiing, boating

;

run;

  1. Input data: Run the following code, create work.Travel.

Output data: work.Travel2. In work.Travel2, create two new variables:

Arrival: It’s value is the first part of Arrival_Depart before comma.

Departure: It’s value is the second part of Arrival_Departafter comma.

Write a program to perform the above task.

data Travel;

input Country $1-12 USGate $14-29 Arrival_Depart $31-52;

cards;

Japan San Francisco Tokyo, Osaka

Italy New York Rome, Naples

Australia Honolulu Sydney, Brisbane

Venezuela Miami Caracas, Maracaibo

Brazil Rio de Janeiro, Belem

;

run;

  1. Input data: Run the following code, create work.var_list.

Output data: work.var_list2. In this data create a new variable VAR_Name, it’s value is the combination of variable vname and variable vnum. There should be no space in the middle of this new variable VAR_Name.

data var_list;

input vname $1-8 vnum 10-15;

datalines;

ATTR 1

ATTR 2

ATTR 3

ATTR 4

ATTR 5

BAL 201001

BAL 201002

BAL 201003

PAYMENT 201001

PAYMENT 201002

PAYMENT 201003

;

run;