Skip to content

Instantly share code, notes, and snippets.

@Prunus1350
Prunus1350 / Koch_curve.sas
Last active December 23, 2015 17:13
gmapプロシジャでコッホ雪片を描く
data koch0;
id = 1; x = cos(constant("pi") * 1 / 6); y = sin(constant("pi") * 1 / 6); density = 0; output;
id = 1; x = cos(constant("pi") * 5 / 6); y = sin(constant("pi") * 5 / 6); density = 0; output;
id = 1; x = cos(constant("pi") * 9 / 6); y = sin(constant("pi") * 9 / 6); density = 0; output;
run;
%macro koch(in1=, out1=, dens=);
proc datasets library = work nolist;
@Prunus1350
Prunus1350 / final_fantasy_kuro.sas
Created June 8, 2015 11:40
黒魔道士のドット絵を描く
data kuro;
input (var1 - var1024) ($);
cards;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 k l 6 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 k k l o 6 0 0 0 0 0
@Prunus1350
Prunus1350 / final_fantasy_shiro.sas
Created June 8, 2015 11:39
白魔道士のドット絵を描く
data waku;
do y = 1 to 32;
do x = 1 to 32;
output;
end;
end;
run;
data attrmap1;
retain id "id1"
@Prunus1350
Prunus1350 / draw_prin.sas
Last active August 29, 2015 14:18
kaggleの手書き文字データのクラス別主成分を描画
%let home_dir = /folders/myfolders/kaggle/DigitRecognizer/;
* trainingデータ読み込み ;
data train;
infile "&home_dir.train.csv" dsd missover firstobs = 2;
input label pixel0 - pixel783;
run;
* 描画用テンプレート作成 ;
proc template;
@Prunus1350
Prunus1350 / inv_matrix.sas
Created March 21, 2015 06:10
DS2 Languageで逆行列
%macro inv_matrix(in1=, out1=);
%local i;
proc contents data = &in1. out = __m1(keep=name varnum nobs) noprint;
run;
* 変数名・行数・列数をマクロ変数に格納 ;
data _null_;
set __m1 end = eof;
@Prunus1350
Prunus1350 / draw_digit.sas
Last active August 29, 2015 14:16
kaggleの手書き文字データを可視化する
%let home_dir = /folders/myfolders/kaggle/DigitRecognizer/;
* trainingデータ読み込み ;
data train;
infile "&home_dir.train.csv" dsd missover firstobs = 2;
input label pixel0 - pixel783;
run;
proc template;
define statgraph digit;
@Prunus1350
Prunus1350 / mult_matrix.sas
Last active August 29, 2015 14:14
DS2 Languageで行列の積
%macro mult_matrix(in1=, in2=, out1=);
%local i j;
%do i = 1 %to 2;
proc contents data = &&in&i.. out = __m&i.(keep=name varnum nobs) noprint;
run;
* 変数名・行数・列数をマクロ変数に格納 ;
data _null_;
@Prunus1350
Prunus1350 / Box-Muller.sas
Created January 14, 2015 19:00
Box-Muller法によるガウス乱数の生成
data rand_normal;
do i = 1 to 1000;
y1 = sqrt(-2 * log(rand("uniform"))) * cos(2 * constant("pi") * rand("uniform"));
y2 = sqrt(-2 * log(rand("uniform"))) * sin(2 * constant("pi") * rand("uniform"));
output;
end;
run;
proc sgplot data = rand_normal;
histogram y1;
@Prunus1350
Prunus1350 / pi_n.sas
Last active August 29, 2015 14:13
モンテカルロシミュレーションで円周率を求める(D次元対応版)
%macro pi(dim=, rep=);
data pi;
do i = 1 to &rep.;
%do j = 1 %to &dim.;
x&j. = rand("uniform") ** 2;
%end;
dist = sqrt(sum(of x:));
if dist <= 1 then cnt + 1;
calc_pi = ((cnt / i) * (2 ** &dim.) * gamma(&dim. / 2 + 1)) ** (2 / &dim.);
@Prunus1350
Prunus1350 / pi.sas
Created January 4, 2015 10:34
円周率を求める
data _null_;
do i = 1 to 100000000;
x = rand("uniform");
y = rand("uniform");
if x ** 2 + y ** 2 <= 1 then cnt + 1;
end;
pi = cnt * 4 / 100000000;
put pi = ;
run;