![](/style/images/good.png)
![](/style/images/bad.png)
SASでWORDLE(その3:SAS/AF)
source link: https://japelin.hatenablog.com/entry/2022/03/17/020051
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
我輩はブロガーではない。ネタもまだない
SASとかDelphiあたりの人様の役に立たないネタを提供します
さてさて、SASでWORDLEというネタを引っ張ってきましたが、最後、SAS/AFでやるとどうなるでしょうか。
SAS/AFの場合、いわゆるアプリケーションとしてのFrameと、ちと古臭いProgram Screenがありますが、せっかくなのでProgram Screenでやってみたいと思います。
ソース付きカタログを以下に置いておくので、試したい方はどうぞ。SAS/AFのライセンスがなくても実行はできます。
https://bitbucket.org/t_kawakami/wordle_sas/src/master/
まず、任意のライブラリにカタログを作成し、Program Screenを新規作成します。
画面の構成はこんな感じです
白だと見づらいので、背景を黒くしています。
コマンドバーから
color background black
と実行します。
また、入力欄はわかりやすくするために、白の反転としています。
ここは、フィールド「&KWRD」を選択して同じ用にコマンドを
color mtext white r
と実行します。
また、文字は、選択後に
color mtext white
のコマンドで白くしています。
さて、次は一般属性です。
ツール>一般属性から以下のように指定します。
少なくとも、行数と列数を指定しないと、全画面になってしまいます。
一般属性を閉じたらツール>フィールド属性を開きます。
フィールド属性を下にスクロールすると、タイプ:ACTIONのフィールドが出てきます。
これは「&」のフィールドです。
入力した結果を表示したいので、保護=YES、オプションのCAPSをON、エイリアスは、配列で扱いたいので「RES+行+列」という名前に変更しておきます。
最後、ツール>ソースウィンドウでsclコードを書きます。
(ここでは、WORK.LISTの4obs目を使用するようになっています)
- 画面に入力した文字を表示するために配列として処理
- fieldコマンドで処理したいので配列の内部変数名(resXX)を別の変数名(fieldname)にフィールド名として格納して処理
- fieldコマンドで反転色を設定
あたりでしょうか。
max6回なので、6回以上できないように、また、成功したら入力欄を保護する、という処理も入れています。
ま、アプリケーションですから最低限の処理ということで。
length answer $5 fieldname $5 ; init: control always label; rc=rc; execcnt=0; success=0; resobs=4; array res{30} $1 res11-res15 res21-res25 res31-res35 res41-res45 res51-res55 res61-res65; lid_answer=makelist(5); dsid=open('WORK.LIST','I'); if dsid>0 then do; rc=fetchobs(dsid,resobs); if rc=0 then do; answer=getvarc(dsid,1); /*リストに保存*/ do i=1 to 5; lid_answer=setitemc(lid_answer,substr(answer,i,1),i); end; end; rc=close(dsid); end; return; main: if length(KWRD)=5 and execcnt<6 and success=0 then do; execcnt+1; success=1; do i=1 to 5; idx=SEARCHC(lid_answer,substr(upcase(KWRD),i,1)); fieldname=cats('res',execcnt,i); res{5*(execcnt-1)+i}=substr(upcase(KWRD),i,1); if idx=0 then do; rc=field('color grey r',fieldname); success=0; end; else if idx=i then do; rc=field('color green r',fieldname); end; else do; rc=field('color yellow r',fieldname); success=0; end; end; KWRD=''; if success then do; rc=field('protect','KWRD'); end; end; return; KWRD:return; term:return;
最後に、実行>コンパイルしてエラーがないことを確認したら、実行します。
右クリックでもいいですし、以下のプログラムを実行してもOKです
proc display c=temp.wordle.wordle.program; run;
こんなアプリケーションウィンドウが立ち上がりました。
入力するとこんな感じです。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK