# sas homework Solutions

Topics: Data set, State, Statistics Pages: 6 (746 words) Published: December 15, 2014
﻿Homework 5 - Solutions

1. Download the external file HW5-States.txt from the Blackboard. Read it into SAS. It contains the Statehood Order, State Name, and Statehood Date. Finish the following tasks.

Calculate the days and years between the statehood date and the Independence Day (4th of July, 1776) for each state. For each state, what is its Bicentennial?
Summarize the number of statehood for each month (January to December, ignore the year). Note: only one row is expected for each month for your final result.

You need to write SAS programs to finish the above tasks. Show your programs and results.

data states;
infile cards dlm="#" firstobs=2;
length Order \$2. State \$20. Date \$20.;
input Order \$ State \$ Date \$;
cards;
1#Delaware#December 7, 1787
2#Pennsylvania#December 12, 1787
3#New Jersey#December 18, 1787
4#Georgia#January 2, 1788
5#Connecticut#January 9, 1788
6#Massachusetts#February 6, 1788
7#Maryland#April 28, 1788
8#South Carolina#May 23, 1788
9#New Hampshire#June 21, 1788
10#Virginia#June 25, 1788
11#New York#July 26, 1788
12#North Carolina#November 21, 1789
13#Rhode Island#May 29, 1790
14#Vermont#March 4, 1791
15#Kentucky#June 1, 1792
16#Tennessee#June 1, 1796
17#Ohio#March 1, 1803
18#Louisiana#April 30, 1812
19#Indiana#December 11, 1816
20#Mississippi#December 10, 1817
21#Illinois#December 3, 1818
22#Alabama#December 14, 1819
23#Maine#March 15, 1820
24#Missouri#August 10, 1821
25#Arkansas#June 15, 1836
26#Michigan#January 26, 1837
27#Florida#March 3, 1845
28#Texas#December 29, 1845
29#Iowa#December 28, 1846
30#Wisconsin#May 29, 1848
31#California#September 9, 1850
32#Minnesota#May 11, 1858
33#Oregon#February 14, 1859
34#Kansas#January 29, 1861
35#West Virginia#June 20, 1863
39#North Dakota#November 2, 1889
40#South Dakota#November 2, 1889
41#Montana#November 8, 1889
42#Washington#November 11, 1889
43#Idaho#July 3, 1890
44#Wyoming#July 10, 1890
45#Utah#January 4, 1896
46#Oklahoma#November 16, 1907
47#New Mexico#January 6, 1907
48#Arizona#February 14, 1912
50#Hawaii#August 21, 1959
;
run;
data states;
set states;
length Month \$10.;
Month=scan(Date, 1);
Day=scan(Date, 2);
Year=scan(Date, 2, ",");
if Month = "January" then Month_Num = 1;
else if Month = "February" then Month_Num = 2;
else if Month = "March" then Month_Num = 3;
else if Month = "April" then Month_Num = 4;
else if Month = "May" then Month_Num = 5;
else if Month = "June" then Month_Num = 6;
else if Month = "July" then Month_Num = 7;
else if Month = "August" then Month_Num = 8;
else if Month = "September" then Month_Num = 9;
else if Month = "October" then Month_Num = 10;
else if Month = "November" then Month_Num = 11;
else if Month = "December" then Month_Num = 12;
Date_Num=mdy(Month_Num, Day, Year);
format Date_Num date9.;
drop Day Year;
run;
data states;
set states;
date_diff=intck('day','04Jul1776'd, Date_Num);
year_diff=yrdif('04Jul1776'd, Date_Num, 'ACT/ACT');
run;
data states;
set states;
Bicentennial=intnx('year',Date_Num, 200);
format Bicentennial date9.;
run;
proc sort data=states;
by Month_Num;
run;
data states_cnt;
set states;
by Month_Num;
if first.Month_Num then Count=1;
else Count+1;
if last.Month_Num then output;
keep Month Count;
run;

Data Set 1

Data Set 2

Data Set 3

Create a Data Set as

data data_q1;
merge data_3(in=a) data_1;
by LName FName;
if a;
format DOB mmddyy8.;
run;

Create a Data Set as

data data_q2;
merge data_3(in=a) data_1(in=b) data_2(in=c);
by LName FName;
if a and b and c;
run;

Create a Data Set as

proc append base=data_1 data=data_3 force;
run;
proc sort data=data_1 nodupkey;
by LName FName;
run;

***** Overall Code *****

data...