*
; options charcode ; /*-------------------------------------------------------------------*/ /* Program: MakeAttr SAS */ /* Purpose: Writes SAS code to recreate a dataset. Useful for */ /* inserting or modifying variables. */ /* Notes: Runs on most (all?) SAS v6.x platforms. */ /* Taken from the Oct92 issue of the PharaSUG newsletter. */ /* Updated: 10-Mar-93, GAT */ /* - initial version. */ /*-------------------------------------------------------------------*/ /*-------------------------*/ /* CHANGE THIS TO TASTE. */ /*-------------------------*/ %Let DSN = inlib.dsn ; /*----------------------*/ /* Generate contents. */ /*----------------------*/ proc contents data = &DSN noprint out = CONTENTS ; proc sort data = CONTENTS ; by LibName MemName NPos ; /*------------------------------------------------*/ /* Generate SAS statements to recreate dataset. */ /*------------------------------------------------*/ data _null_ ; attrib Label length=$40 ; set CONTENTS (rename=(Label=tmplabel)) ; by LibName MemName ; file 'MAKEATTR.INC' ; /*-----------------*/ /* Dataset name. */ /*-----------------*/ if (first.MemName) then do ; dsn = trim(LibName) ?/?/ '.' ?/?/ MemName ; put 'data ' dsn ' ;' ; end ; /*------------------*/ /* Variable name. */ /*------------------*/ put @5 'attrib ' Name ' length=' @ ; if (Type = 2) then put '$' @; /*---------------------------------*/ /* Length, informat, and format. */ /*---------------------------------*/ put Length @ ; if (InformL = 0) then if (Informat > '') then InformL = Length ; if (InformL > 0) then do ; Informat = left(Informat) ; put ' informat=' Informat +(-1) InformL +(-1) '.' @ ; end ; if (FormatL > 0) then do ; Format = left(Format) ; put ' format=' Format +(-1) FormatL +(-1) '.' @ ; if (FormatD > 0) then put FormatD @ ; end ; /*-------------------*/ /* Variable label. */ /*-------------------*/ indx = 1 ; chunk = scan(tmplabel, 1, "'") ; Label = '' ; do while (chunk > '') ; Label = left(Label) ?/?/ "''" ?/?/ left(chunk) ; indx + 1 ; chunk = scan(tmplabel, indx, "'") ; end ; Label = substr(Label, 3) ; put / @10 'label=''' Label $char40. ''' ;' ; if (last.MemName) then do ; put @5 "set &DSN ;" / 'run ;' ; end ; run ; dm 'pgm; inc "makeattr.inc"; zoom on' pgm ; *;