05-25-2016 12:49 PM
how to read 'len' from PROC CONTENTS ? I have 368 attributes with diff legth and formats .
I tried doing PROC CONTENTS and SQL to get the lengths in col_widths.
proc contents data = output_xlsd out =output_contents; run;
Proc SQL noprint;
Select len into: col_widths separated by "," From output_contents; Quit;
I am getting error as 'len; not found as it is not present in the output_contents dataset. How to get the lengths of all attributes with simple logic?
05-25-2016 01:22 PM
You already did, without needing SQL. Take a look at the output data set from PROC CONTENTS. For example, you could try:
proc print data=output_contents;
var name length;
You have the information, you just have to figure out how to use it.
05-26-2016 09:08 AM
It would be interesting to know the Why of this. I mean theoretcially you could put all the lengths into macro variables and go that way, but as the SAS metadata can be accessed like a dataset it seems a bit of a faff. Say for instance you want to standardise the length of all character variables to 200 and numerics to 8:
set sashelp.vcolumn (where=(libname="SASHELP" and memname="CLASS")) end=last;
if _n_=1 then call execute('data want; length');
call execute(cat(' ',strip(name),ifc(type="char",' $200',' 8')));
if last then call execute('; set sashelp.class; run;');