我輩はブロガーではない。ネタもまだない

SASとかDelphiあたりの人様の役に立たないネタを提供します

SASでWORDLE(その2:UI追加)

SASでWORDLE - 我輩はブロガーではない。ネタもまだない
この追記です。

ベタですけど、%windowを使ってUIを作りました。

リストの作成のところは同じ

%let keychars=5;
%let resobs=4;
data list;
  length wordle $&keychars.;
  input wordle;
datalines;
PIZZA
QUICK
QUAKE
CRAZY
CHICK
WALTZ
;
run;


で、本題はここから。
%windowで入力欄を呼び出し、入力された内容をマクロ変数として、処理用のマクロに引き継いでいます(パラメータではないですけど)

%window wordleWindow
  color=gray
  icolumn=40
  irow=10
  rows=40
  columns=60
#1 @1 "Welcome to WORDLE in SAS"
#4 @8 "Enter 5 charactors and press Enter"
#6 @8 input 5 attr=underline REQUIRED=yes
;

%Macro Wordle;

  %display wordleWindow;  

  options nomprint nomlogic nonotes nosource;
  title ;
  %if %length(&input)^=&keychars %then %do;
  data _null_;
    file print;
    put 'not 5 charactors!';
  run;

  %end;%else
  %do;
    data res;
      %let success=1;
      set list(firstobs=&resobs obs=&resobs);
      length res1-res5 $2;
      %do i=1 %to &keychars;
        res&i=cats(char(upcase("&input"),&i),index(wordle,char(upcase("&input"),&i)));
      %end;
      keep res:;
    run;
  
    ods html;
    proc report data=res nowd noheader
      style(column)={FONT_SIZE=12pt WIDTH=20 TEXTALIGN=center FONT_WEIGHT=bold COLOR=white};
      column res: ;
      %do i=1 %to &keychars;
        compute res&i;
               if substr(res&i,2)="0"  then call define (_COL_,'style','style={background=gray}');
          else if substr(res&i,2)="&i" then call define (_COL_,'style','style={background=green}'); 
          else                              call define (_COL_,'style','style={background=D1C513}'); 
          res&i=substr(res&i,1,1);
        endcomp;
      %end;
    run;
  %end;
  %let input=;

%Mend;  

これで、

%Wordle

を実行するだけで以下のウィンドウが立ち上がります。



で、このように入力してenterを押せば…

結果が出力されます


後は6回の制限だったり、正解したら処理できなくしたり、といったエラー処理は…やめときましょう。

なお、残念ながらSAS Studioでは%Windowが動かないので使えません。