Hello Jerry
The following code splits the create statement and extracts Column names and types. The Table name is extracted as the third word using SCAN, and the Column definitions are extracted using a regular expression, that looks for a word in quotes followed by one space followed by an unquoted word optionally followed by a block containing only digits, parantheses or comma. The expression also finds the keys, and they are omitted because the words PRIMARY and FOREIGN are not valid Column types.
data have;
line = 'CREATE TABLE "TEMP" ("TEMPID" NUMBER(7,0), "TESTID" NUMBER(6,0), "TYPE" VARCHAR2(5), "STARTDT" DATE, "SOURCE" VARCHAR2(5), "TITLE" VARCHAR2(6), CONSTRAINT "TEMP_PK" PRIMARY KEY ("TEMPID") ENABLE, CONSTRAINT "TEMP_FK" FOREIGN KEY ("KEYID") REFERENCES "KEY" ("ID") ENABLE) ;';
run;
data want (keep=TABNm COLNm COLType); set have;
length w $200 TABNm COLNm COLType $60;
TABNm = dequote(scan(line,3,' '));
xpr = prxparse('/"\w+"\s{1}\w+[\d,\(\)]*/');
start = 1;
stop = length(trim(line));
call prxnext(xpr, start, stop, line, pos, len);
do while (pos > 0);
w = substr(line, pos, len-1);
COLNm = dequote(scan(w,1,' '));
COLType = dequote(scan(w,2,' '));
if substr(COLType,1,4) not in ('PRIM','FORE') then output;
call prxnext(xpr, start, stop, line, pos, len);
end;
run;
The result is:
TEMP TEMPID NUMBER(7,0)
TEMP TESTID NUMBER(6,0)
TEMP TYPE VARCHAR2(5)
TEMP STARTDT DATE
TEMP SOURCE VARCHAR2(5)
TEMP TITLE VARCHAR2(6)
... View more