DATA Step, Macro, Functions and more

Proc Puzzle

Reply
Respected Advisor
Posts: 4,925

Proc Puzzle

This is a followup to an interesting discussion that was initiated in SAS Australia & New Zealand Online Community (SANZOC). See . I liked the challenge of using SAS code to solve a word puzzle. Here is my proposal:

data str;

length str $101 set car $1;

input str;

L = _n_;

do C = 1 to length(str);

    car = char(str, C);

/* Create horizontal, vertical and both diagonal reading orderings */

    set="A"; v1=C; v2=L; output;

    set="B"; v1=L; v2=C; output;

    set="C"; v1=C-L; v2=C; output;

    set="D"; v1=L+C; v2=L; output;

    end;

keep set v1 v2 car;

datalines;

YLWYFNECBSKRVMN

JTTMPDSBJNKWQEU

BMCMOCOAARNNDAR

QZKLHJPRKLZAONA

PIPANNSDELETESA

QXRXQBNMRVMJRWC

ETLSSCAXEUOSGOI

AMVBNARKEYUGKGS

XXQGCATMKAJGYZA

GKPNYDCSSQBMROH

YXYRAOCNHTROPCA

AJDNISZKNPRLHLK

TYVFRNMPCMQXREX

RSDDHJTWXCEMTWT

RRUZFTDXAFVPNCT

;

proc sort data=str; by set v1 v2; run;

data long;

length long $10000;

retain long;

set str end=done; by set v1;

if first.v1 then pos + 1; /* Separate lines, columns and diagonals with spaces */

pos + 1;

substr(long, pos, 1) = car;

if done then output;

keep long;

run;

data procs;

if _n_=1 then set long;

infile "&sasforum\datasets\procNames.txt"; /* Attached file */

input procName :$16.;

found = find(long, trim(procName)) > 0 or find(long, reverse(trim(procName))) > 0;

keep procName found;

run;

proc print data=procs; where found; run;

Result: there are 10 proc names in the character array.

PG

PG
Attachment
Ask a Question
Discussion stats
  • 0 replies
  • 123 views
  • 0 likes
  • 1 in conversation