%let Ctx = "LotId;P110123; DuploWaferId;D02; Operation; 1000-OxideDepostion!1!0"; In this example this are always pairs. I want a table with columns LotId DuploWaferId Operation with the correct values. I tried already a few things, but what is the best way? %let CtxFormat="CtxName;CtxValue"; %let Ctx = "LotId;P110123; DuploWaferId;D02; Operation; 1000-OxideDepostion!1!0"; data _null_; aantal = %sysfunc(countw(&CtxFormat,';')); call symputx('aantal',aantal); run; %put &aantal; data _null_; aantal = %sysfunc(countw(&Ctx,';')); call symputx('aantalvar',aantal); run; %put &aantalvar; data format; array format{&aantal} $20.; i = 1; do while (scan(&CtxFormat,i,';') NE ''); format{i} = scan(&CtxFormat,i,';'); i = i +1; end; run; data colnames(keep=vname); set format (obs=1) ; array n{*} _NUMERIC_ ; array c{*} _CHARACTER_ ; do i = 1 to dim(n) ; vname = vname(n{i}) ; output ; end ; do i = 1 to dim(c) ; vname = vname(c{i}) ; output; end ; run ; proc sql; select vname into:cols separated by ' ' from colnames where vname ne 'i'; quit; %put &cols; proc transpose data=format out=formattransp(keep=format1) prefix=format; var &cols; by i; run; data _null_; set formattransp; if upcase(format1) = "CTXNAME" then call symputx('PlaceName',_N_); if upcase(format1) = "CTXVALUE" then call symputx('PlaceValue',_N_); run; %put &PlaceName &PlaceValue; /* read values */ /* aantal = number of blocks per variable */ /* aantalvar = number of variables in ctx */ /* PlaceName = Place of the name of the variable */ /* PlaceValue = Place of the value of the variable */ data temp_variables; array format{&aantalvar} $50.; i = 1; do while (scan(&Ctx,i,';') NE ''); format{i} = compress(scan(&Ctx,i,';')); i = i +1; end; run; data colnames(keep=vname); set temp_variables (obs=1) ; array n{*} _NUMERIC_ ; array c{*} _CHARACTER_ ; do i = 1 to dim(n) ; vname = vname(n{i}) ; output ; end ; do i = 1 to dim(c) ; vname = vname(c{i}) ; output; end ; run ; proc sql; select vname into:cols separated by ' ' from colnames where vname ne 'i'; quit; %put &cols; proc transpose data=temp_variables out=temp_variables_transp(keep=format1) prefix=format; var &cols; by i; run; data column_names(drop=teller) column_values(drop=teller); set temp_variables_transp; retain teller; if _N_ = 1 then teller = 1; if teller = &PlaceName then output column_names; if teller = &PlaceValue then output column_values; if mod(_N_,&aantal) = 0 then do; teller = 0; end; teller = teller + 1; run; proc sql; select format1 into:columns separated by ' ' from column_names; quit; %put &columns;
... View more