#Question 1
# a. Write a SAS program to create a temporary SAS data set called Vote.
# Use the variable name State, Party and Age. Age should be stored as a numeric variable,
# State and Party should be stored as character variables.
# b. Include a procedure to list the observations in this data set.
# c. Include a procedure to compute frequencies for Party.
# d. Repeat problem above (a to c) using R programming
setwd("D:/Rstudio Project")
Vote2
<- read.csv(file = 'D:/Rstudio Project/Sas Week 12/political.csv', header
=FALSE , sep
=',')
colnames(Vote2
) <- c("State" ,
"Party",
"Age") #change column names
View(Vote2
) #list all observation
print(Vote2
) #list all observation
#calculate frequency
#Method 1
#Method 2
# Question 2
# Using the Bicycle data set (SAS native dataset), list all the
# observations for Road Bike that cost more than $2,500 or Hybrid
# that cost more than $660. The variable Model contains the type of bike
# and UnitCost contains the cost.
#teachers way, using sa7bdat library
bicycles2
<- read.
sas7bdat(file = 'D:/Rstudio Project/Sas Week 12/bicycles.sas7bdat')
outpl
<- subset(bicycles2,
(Model
=='Road Bike' & UnitCost
> 2500 | Model
=='Hybrid' & UnitCost
> 660), select
=Country
:Manuf
)
#own way
bicycles <- read_sas("bicycles.sas7bdat", + NULL)
sqldf("select * from bicycles where Model = 'Road Bike' and UnitCost > 2500 or Model = 'Hybrid' and Unitcost >660") #get the result using sql
RoadBike <- bicycles[bicycles$UnitCost > 2500 & bicycles$Model == "Road Bike" ,] #get the result for roadbike
Hybrid <- bicycles[bicycles$UnitCost > 660 & bicycles$Model == "Hybrid" ,] #get the result for roadbike
Mergedbike
<- merge(Hybrid,RoadBike,
all = TRUE
) #merge both datsets together
#Question 3
# Create a temporary SAS data set called Bank using this data file. Use using formatted
# input to read the data values. Include in this data set a variable called Interest
# computed by multiplying Balance by Rate. List the contents of this data set using
# PROC PRINT.
bankdata <- read_table2("bankdata.txt", col_names = FALSE)
bankdata <- unite(bankdata, Name, X1, X2, sep = " ")
bankdata$Rate <- 0
colnames(bankdata
) <- c("Name" ,
"Acct",
"Balance",
"Rate")
bankdata$Interest <- bankdata$Balance * bankdata$Rate
#teachers solution
bankR
<- read.fwf('D:/Rstudio Project/Sas Week 12/bankdata.txt', width
=c(15,
5,
6,
4), col.
names = c("Name" ,
"Acct",
"Balance",
"Rate"))
bankR$interest = bankR$balance = bankR$rate
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}