This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* sum of two variables in SAS ; | |
data output ; | |
set input ; | |
z = x + y ; | |
run ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sum of two variables in R | |
input$z <- input$x + input$y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bank_count <- bank | |
bank_count$condition <- bank_count$Expense > 40 | |
bank_count <- aggregate(bank_count$condition, by = list(bank_count$CardID), FUN = sum) | |
names(bank_count) <- c("CardID", "over_spend") | |
bank_count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bank_sum <- aggregate(bank$Expense, | |
by = list(bank$CardID), | |
FUN = sum) | |
names(bank_sum) <- c("CardID", | |
"total_expense") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bank_mod <- reshape(bank, | |
v.names = "Expense", | |
idvar = "CardID", | |
timevar = "month", | |
direction = "wide") | |
names(bank_mod) <- gsub("\\.", "", names(bank_mod)) | |
bank_mod <- bank_mod[, c("CardID", "Expense1", "Expense2", "Expense3")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CardID <- c(1, 1, 1, 2, 2, 2) | |
month <- c(3, 2, 1, 3, 2, 1) | |
Expense <- c(100, 50, 70, 20, 30, 60) | |
bank <- data.frame(cbind(CardID, month, Expense)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data bank_count (keep = CardID over_spend) ; | |
set bank ; | |
by CardID ; | |
retain over_spend ; | |
if first.CardID then over_spend = 0 ; | |
if Expense > 40 then over_spend = over_spend + 1 ; | |
if last.CardID ; | |
run ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data bank_sum (keep = CardID total_expense) ; | |
set bank ; | |
by CardID ; | |
retain total_expense ; | |
if first.CardID then total_expense = 0 ; | |
total_expense = total_expense + Expense ; | |
if last.CardID ; | |
run ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data bank_mod (drop = i month Expense) ; | |
set bank ; | |
by CardID ; | |
if _n_ = 1 then do ; | |
array Expensex(3) Expense1 - Expense3 ; | |
end ; | |
retain Expense1 - Expense3 ; | |
if first.CardID then do ; | |
do i = 1 to 3 ; | |
Expensex(i) = . ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data bank ; | |
input CardID month Expense ; | |
datalines ; | |
1 3 100 | |
1 2 50 | |
1 1 70 | |
2 3 20 | |
2 2 30 | |
2 1 60 | |
run ; |