Skip to content

Instantly share code, notes, and snippets.

Lixun lixzhang

Block or report user

Report or block lixzhang

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View sum.SAS
* sum of two variables in SAS ;
data output ;
set input ;
z = x + y ;
run ;
View sum.R
# sum of two variables in R
input$z <- input$x + input$y
View countByID.R
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
View sumByID.R
bank_sum <- aggregate(bank$Expense,
by = list(bank$CardID),
FUN = sum)
names(bank_sum) <- c("CardID",
"total_expense")
View reshape.R
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")]
View loadData.R
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))
View countByID.sas
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 ;
View sumByID.sas
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 ;
View reshape.sas
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) = . ;
View loadData.sas
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 ;
You can’t perform that action at this time.