BookmarkSubscribeRSS Feed
SASAna
Quartz | Level 8

 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?

 

Thanks,

Deepa

 

 

 

 

5 REPLIES 5
FreelanceReinh
Jade | Level 19

The relevant variable name in output_contents is LENGTH, not LEN.

JediApprentice
Pyrite | Level 9

So, are you trying to get the lengths assigned to a new variable (col_widths)? 

Astounding
PROC Star

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;

run;

 

You have the information, you just have to figure out how to use it.

SASAna
Quartz | Level 8
Thanks all
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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:

data _null_;
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;');
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1488 views
  • 1 like
  • 5 in conversation