So my code, which works up until the actual macro at the end, seems fine in theory, but I feel like SAS is not a fan of using the macro variables inside of the format options. Below is my code, everything up until the macro works. (Pardon the casing, I write in caps, but the first part of code I found in lowercase). data inter; set have; array chars _character_; length __varname $32; do over chars; __varname=vname(chars); __length=lengthn(chars); output; end; run; proc sql; create table want as select __varname as varname, max(__length) as max_length from inter group by varname ; quit; PROC SQL; SELECT COUNT(DISTINCT VARNAME) INTO :VARCNT TRIMMED FROM WORK.WANT; PROC SQL; SELECT COMPRESS(VARNAME) INTO :VRNM1 - :VRNM&VARCNT FROM WORK.WANT; PROC SQL; SELECT MAX_LENGTH INTO :ML1 - :MX&VARCNT FROM WORK.WANT; %MACRO CLEAN; %DO i = 1 %TO &VARCNT; PROC SQL; ALTER TABLE HAVE MODIFY &&VRNM&i CHAR(&&ML&i.) FORMAT=$&ML&i. QUIT; %END; %MEND; %CLEAN; I tried different variations of "&"s and "."s but could not find one that worked.
... View more