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
/*This code is from SAS Communities question: | |
https://communities.sas.com/t5/Base-SAS-Programming/Reflexive-join-but-limit-some-of-the-joining/m-p/255561 | |
*/ | |
%let rad = constant('pi') / 180; /*degrees to radians*/ | |
%let r_km = 6371; /*radius of the earth in km (3959 miles)*/ | |
proc fcmp outlib = work.funcs.haversine; | |
function haversine(lat1, long1, lat2, long2); /*function name*/ | |
/*function definition*/ |
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
/* | |
Author: F. Khurshed | |
Date: June 17, 2011 | |
Purpose: This macro creates a set of chisquare tables appended together. It includes the chisquare value. | |
January 17, 2012 | |
*Adding in the ability for the macro to add the total column | |
February 6, 2012 | |
*Add in row of overall by cross category |
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
%macro lag(vars, lags); | |
%let m = %sysfunc(countw(&vars)); | |
%do i=1 %to &m; | |
%let var = %scan(&vars,&i); | |
%do j=1 %to &lags; | |
%do; | |
lag_&var.&j = lag&j(&var); | |
%end; |
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
*Extract n lines to a new file; | |
gc -path file_name.csv - head N > output.txt | |
*Get the number of lines in a text file; | |
Get-Content "Path to file"| Measure-Object -Line |
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 class; | |
set sashelp.class; | |
label name="NAme" sex="GEndeR" age="Age" height="HeiGht" weight="kilograms"; | |
run; | |
proc sql noprint; | |
select catx('=', name, quote(propcase(coalescec(trim(label), name)))) | |
into :label_list separated by " " from sashelp.vcolumn where libname='WORK' | |
and upper(memname)='CLASS'; | |
quit; |
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 random_sentences; | |
infile cards truncover; | |
informat sentence $256.; | |
input sentence $256.; | |
cards; | |
This is a random #sentence | |
This is another #random sentence | |
Happy Birthday #test#together | |
My job#sucks. | |
This is a good idea, not. |
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
/*This code demonstrates how to keep only duplicate observations in a data set*/ | |
%*Create sample data set; | |
data have; | |
informat name $80.; | |
input name $ found; | |
cards; | |
If_True 1 | |
If_True_kary 1 | |
If_True_kary 1 |
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
/*this is an example of time series data. | |
1. Create a time series data set with missing intervals (IBM) | |
2. Add back missing entries using PROC TIMESERIES (IBM_NO_MISSING) | |
3. Calculate moving average - 12 month average | |
*/ | |
/*1*/ | |
data ibm; | |
set sashelp.stocks; | |
where stock='IBM'; |
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
*create a sample data set; | |
data have; | |
do i=1 to 7000; | |
x=rand('bernoulli', 0.4); | |
output; | |
end; | |
run; | |
*Set group size; | |
%let group_size = 1000; |
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
/*How to create 50 random numbers for every observation in your data set */ | |
data want; | |
set sashelp.class; | |
do i=1 to 50; | |
zv = rannor(0); | |
output; | |
end; |