投稿

2014の投稿を表示しています

特定のformatに対して処理をしたい - SAS

特定のformatの項目にだけ処理を行う方法。 SASさんは、日付型がなくて、日付は数値項目(_numeric_)として格納している。 日付に対して、一律処理を行いたかったのだけど、_date_みたいなのはないです。 日付が入っている項目のformatが全て同じ場合しか使えないけど、vformat関数を使えばできそうです。 array ○○ _numeric_ で数値項目を取得して、do over を使って、一項目ずつ処理を実施する。 文字項目の場合は、array 〇〇 _character_ で取得する。 vformat関数で、引数のformatを取り出す。 vformatは、英数字の「大文字」で返すぽい。 コード /* テストデータ */ data test ; format a yymmddn8. ; a = "16jan86"d ; b = "aaaaa" ; c = 1234 ; run ; data test ; set test ; array TMP_NUM _numeric_ ; /* 数値項目を配列に格納 */ do over TMP_NUM ; _format = vformat(TMP_NUM) ; /* 変数のformatを格納(英数字大文字) */ _name = vname(TMP_NUM) ; /* 変数名を格納 */ putlog _name _format ; /* 特定のformatだけ処理する */ if (_format = "YYMMDDN8.") then putlog "correct!" ; else putlog "false" ; end ; run ; ログ a YYMMDDN8. correct! c BEST12. false 2015/05/15追記: テストデータが、0オブザベーションのとき実行されないじゃないか、ということで改善版の記事を書きました。 「0 オブザベーションのデータセットに

「小数点以下の桁数を指定して切り捨てを行なう方法」が上手く行かなかった話 - SAS

「 小数点以下の桁数を指定して切り捨てを行なう方法 」がSAS社のQAにあったので試したところ、上手く行かなかった。 大旨、うまくいくのだけれど、一部の値がおかしな結果になるみたい。 サンプルプログラム1 data test ; input a ; cards ; 10 10.1 10.12 10.25 10000 123.123 9.9 9.99999 -100 -10.1 -1.12 -1.000 260.9 260.4 run ; data _null_ ; set test ; b = a * 100 ; c = int(b) ; d = c / 100 ; putlog a= b= c= d= ; run ; 実行ログ1 a=10 b=1000 c=1000 d=10 a=10.1 b=1010 c=1010 d=10.1 a=10.12 b=1012 c=1012 d=10.12 a=10.25 b=1025 c=1025 d=10.25 a=10000 b=1000000 c=1000000 d=10000 a=123.123 b=12312.3 c=12312 d=123.12 a=9.9 b=990 c=990 d=9.9 a=9.99999 b=999.999 c=999 d=9.99 a=-100 b=-10000 c=-10000 d=-100 a=-10.1 b=-1010 c=-1010 d=-10.1 a=-1.12 b=-112 c=-112 d=-1.12 a=-1 b=-100 c=-100 d=-1 a=260.9 b=26090 c=26089 d=260.89 a=260.4 b=26040 c=26039 d=260.39 見事に誤差がでてますね。ちなみに、int を floor に変更しても同じ結果。 切り捨てるどころか、むしろ小数桁を増やしてます(´・ω・`) どうも100倍した時点で、期待通りの値になっていないぽいです。 サンプルプログラム2 data _null_ ; a = 260.4 ; b = a * 100 ; c = 26040 ; putlog b= c= ; if a = b then putlog "同じだよ

改行コードを指定してファイルを読み込む termstr - SAS

data test; infile 'test.txt' termstr=lf; input text $; run; termstr= の部分を改行コードに応じて、lf, cr, crlf のいずれかを指定します。 参考サイト Usage Note 14178: INFILE's TERMSTR= option facilitates reading files between UNIX and Windows (英語)

文字コード UTF-8 のファイルの入出力時に、BOM NOBOMを設定する - SAS

UTF-8で出力するファイルに、BOMの有無を設定するオプション data _null_ ; file "test1.txt" dlm="," lrecl=1048576 encoding="UTF-8" BOM ; put A B C ; run ; data _null_ ; file "test2.txt" dlm="," lrecl=1048576 encoding="UTF-8" NOBOM ; put A B C ; run ; 読込みの場合 data _null_ ; infile "test1.txt" dlm="," lrecl=1048576 encoding="UTF-8" BOM ; input A B C ; run ; data _null_ ; infile "test2.txt" dlm="," lrecl=1048576 encoding="UTF-8" NOBOM ; input A B C ; run ;

TEST

%TEST です。 data Memorandum ; set Memory ; run ; data Memorandum ; set Memory ; run ; options msglevel=i lognumberformat ; data TEST ; length A 1. J $10. ; /* テスト */ array TMP{*} _temporary_ VAR1 - VAR10 ; set TEST(where=(Z=0)) ; * テスト ; do A=1 to 1000 ; A1 = TMP(A) ; end ; if B > 1 then C = 1 ; if D gt 1 then E = substr(F, 1, 1) ; if G < DT < I do ; putlog DT= ; end ; call symputx('TEST', "TEST") ; stop ; run ; proc append base=TEST data=TEST1 ; run ; title 'TEST' ; proc print data=TEST label ; run ; /* テスト */ * テスト ; * テスト ; /* * > < & " */ %let TEST = TEST ; %macro TEST() ; %put HELLO --- ; %mend TEST ; filename TEST "/folders/myfolder/test.txt" ; data TEST2 ; infile IN dlm=',' dsd missover lrecl=1048576 ; input A : comma20.2 B : date9. C : $char10. ; ; run ; この投稿はテストです! HTML特殊文字変換ツール <p></p> <p></p>