0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SAS言語備忘録_IMLをFCMPで再現

Last updated at Posted at 2020-03-04

#IMLインストールPCでしか出来ない処理が・・・
定期的に発生する案件でIMLをインストールしていないと実行できないプログラムがありました。
ぶっちゃけIML使わなきゃいけないほど高度な案件とは思えずプログラムを読んでみたらただの2次元配列の計算だったという。
しかもBaseSASでローカルとリモートを行ったり来たりしてて無駄にプログラムが分割されていたので一個にまとめました。
ただ一つ前処理の変更が必要だったのが配列には数字のみしか格納できないので、アルファベットで区分けされてたものを数字に置き換えたくらいですかね。
元のPROC IMLの部分とPROC FCMPの部分だけ抜粋しておきます。

IML.sas
PROC IML
; 

USE t_RKS_JISSEKI_TRANS_OUT2;
READ ALL VAR _NUM_ INTO JISSEKI;
CLOSE t_RKS_JISSEKI_TRANS_OUT2;

*USE WORK.COMMON_FACTOR;
USE R_WORK.COMMON_FACTOR;
READ ALL VAR _NUM_ INTO FACTOR;
CLOSE WORK.COMMON_FACTOR;

USE WORK.ranmtnrm;
READ ALL VAR _NUM_ INTO RANNORM;
CLOSE WORK.ranmtnrm;

RAND_HENDO = RANNORM * FACTOR ;

USE t_RKS_GYO_TRANS_OUT2;
READ ALL VAR _CHAR_ INTO GYOCD;
CLOSE t_RKS_GYO_TRANS_OUT2;
print GYOCD;

USE t_RKS_EXP_TRANS_OUT2;
READ ALL VAR _NUM_ INTO EXP;
CLOSE t_RKS_EXP_TRANS_OUT2;
print EXP;

NCOL_JISSEKI=NCOL(JISSEKI);
print NCOL_JISSEKI;
HENDO_CNT=NROW(RAND_HENDO);
print HENDO_CNT;

RAND_HENDO_1 = RAND_HENDO + 1;

AFTONE=J(HENDO_CNT,NCOL_JISSEKI,0);
SC=1;
EC=1;
 DO WHILE( SC <= HENDO_CNT );
    DO WHILE(EC <= NCOL_JISSEKI);
     IF GYOCD[1,EC] = "E" THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,1];
     IF GYOCD[1,EC] = "F" THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,2];
     IF GYOCD[1,EC] = "G" THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,3];
     IF GYOCD[1,EC] = "H" THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,4];
     IF GYOCD[1,EC] = "I" THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,5];
     IF GYOCD[1,EC] = "J" THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,6];
     IF GYOCD[1,EC] = "L" THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,7];
     EC=EC+1;
    END;
 SC=SC+1;
 EC=1;
 END;

CREATE WORK.AFTONE FROM AFTONE;
APPEND from AFTONE;
CLOSE AFTONE;

QUIT;
FCMP.sas
proc fcmp;
	ARRAY JISSEKI[1,&DS_OBS.] / nosymbols;
	ARRAY FACTOR[1,7] / nosymbols;
	ARRAY RANNORM[10000,2] / nosymbols;
	ARRAY RAND_HENDO[10000,7] / nosymbols;
	ARRAY GYOCD[1,&DS_OBS.] / nosymbols;
	ARRAY EXP[1,&DS_OBS.] / nosymbols;
	ARRAY RAND_HENDO_1[10000,7] / nosymbols;
	ARRAY AFTONE[10000,&DS_OBS.] / nosymbols;
	rc=read_array("t_RKS_JISSEKI_TRANS_OUT2",JISSEKI);
	rc=read_array("COMMON_FACTOR",FACTOR);
	rc=read_array("ranmtnrm",RANNORM);
	call mult(RANNORM,FACTOR,RAND_HENDO);
	rc=read_array("t_RKS_GYO_TRANS_OUT2",GYOCD);
	rc=read_array("t_RKS_EXP_TRANS_OUT2",EXP);
	call addmatrix(RAND_HENDO,1,RAND_HENDO_1);

	SC=1;
	EC=1;
	DO WHILE( SC <= 10000 );
    	DO WHILE(EC <= &DS_OBS);
		    IF GYOCD[1,EC] = 1 THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,1];
    		ELSE IF GYOCD[1,EC] = 2 THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,2];
    		ELSE IF GYOCD[1,EC] = 3 THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,3];
    		ELSE IF GYOCD[1,EC] = 4 THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,4];
    		ELSE IF GYOCD[1,EC] = 5 THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,5];
    		ELSE IF GYOCD[1,EC] = 6 THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,6];
    		ELSE IF GYOCD[1,EC] = 7 THEN AFTONE[SC,EC] = JISSEKI[1,EC] * RAND_HENDO_1[SC,7];
			ELSE AFTONE[SC,EC] = 0;
    		EC=EC+1;
    	END;
 		SC=SC+1;
 	EC=1;
 	END;

	rc=write_array("RAND_HENDO",RAND_HENDO);
	rc=write_array("RAND_HENDO_1",RAND_HENDO_1);
	rc=write_array("AFTONE",AFTONE);
run;
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?