Skip to content

Instantly share code, notes, and snippets.

@statgeek
statgeek / R_increment_dates_lubridate.R
Created September 20, 2019 19:52
R - Increment dates
# 2019-09-20
library(lubridate)
term_start = as.Date("2012-01-01", "%Y-%m-%d")
term_end = term_start + years(5) - days(1)
@statgeek
statgeek / R_finding_duplicates.R
Created September 16, 2019 16:17
R - finding duplicates - tidyverse
##This program illustrates how to find duplicates in your data set for a particular key
##All duplicate records will be indentified
mtcars %>%
group_by(carb) %>%
filter(n()>1)
@statgeek
statgeek / sas_datetime_macro_variable.sas
Last active July 31, 2019 15:41
SAS - datetime stamp for filenames
*This illustrates how to create a datetime stamp in the format of YYYYMMDDHHMM;
%let fileTimeStamp = %sysfunc(date(), yymmddn8.)%sysfunc(putc(%sysfunc(time(), b8601TM6.), $4.)) ;
%put &fileTimeStamp.;
*Results from log;
* 71 %let fileTime = %sysfunc(date(), yymmddn8.)%sysfunc(putc(%sysfunc(time(), b8601TM6.), $4.)) ;
* 72 %put &fileTime.;
* 201907310938;
@statgeek
statgeek / SAS_tagsets_sql_reprex.sas
Created July 17, 2019 02:17
SAS - PROC SQL - create sample data
/*------------------------------------------------------------eric-*/
/*-- This tagset creates sql statements to create a table --*/
/*-- and insert all the records in the dataset. The resulting --*/
/*-- output will have the table create statement followed by --*/
/*-- the insert statements. --*/
/*-- --*/
/*-- This has only been tested with proc print, although it may --*/
/*-- Work with other proc's as well. --*/
/*-- --*/
/*-- This isn't anything fancy, all it handles are strings, --*/
@statgeek
statgeek / 00_calculate_percent_increase.R
Created July 10, 2019 03:35
R - calculate percent of population over 60 by Province
install.packages("cansim")
install.packages("tidyverse")
library("cansim")
library("tidyverse")
pop <- get_cansim("17-10-0005-01")
#keep only relevant data
@statgeek
statgeek / Example_adding_data_reporting_process
Last active February 24, 2021 16:15
SAS - Case Study - How to add data to a regular report and then report on it daily
/*This program illustrates how to build a daily process that will add in your data and then create an automatic report every day
Author: F. Khurshed
Date: 2019-06-18
*/
data have;
input ID : 4. bucket1-bucket3 : 5.2;
format bucket: 5.2;
datalines;
@statgeek
statgeek / sas_variance_test.sas
Created February 10, 2019 00:40
SAS - Hypothesis Test for Variance
/*
Original Source: https://support.sas.com/kb/25/024.html
*/
%macro vartest(version,
data= _last_ ,
var= ,
alpha= 0.05 ,
var0=,
@statgeek
statgeek / SAS_import_statcan_data.sas
Created January 23, 2019 23:36
SAS - Import Statistics Canada Table Numbers
%macro importStatCan(tableNum = , dset= );
filename out "%sysfunc(getoption(work))/&tableNum.-eng.zip";
proc http
url="https://www150.statcan.gc.ca/n1/tbl/csv/&tableNum.-eng.zip"
method="get"
out=out;
run;
@statgeek
statgeek / SAS_time_process_stored.sas
Created January 9, 2019 18:14
SAS - track time processes
proc sql;
create table master_process_time
(Entry char(32),
StartTime num format=datetime22.4,
EndTime num format=datetime22.4,
duration num format=32.4,
recordTime num format=datetime22.4);
quit;
%global startTime endTime;
@statgeek
statgeek / DDE Command Lists
Created January 2, 2019 01:09
DDE - Command Lists
https://d13ot9o61jdzpp.cloudfront.net/files/Excel%204.0%20Macro%20Functions%20Reference.pdf