In SAS I'm trying to figure out how to get output (results or actual dataset) that show me the column name, var length, and max length (which would of course be repeated for each obs with that column name).
Asked
Active
Viewed 651 times
-1
-
1What have you tried so far? SO is not a code writing service, please attempt to solve the problem yourself and explain what you're having issues with. Sample data and expected output also help to explain your problem . – Reeza Aug 02 '17 at 18:58
-
https://stackoverflow.com/help/how-to-ask – Reeza Aug 02 '17 at 18:59
-
Also, see SASHELP.VCOLUMNS table for information. – Reeza Aug 02 '17 at 19:00
-
Try `proc contents` – acylam Aug 02 '17 at 19:09
-
proc contents gives me the output of each variable with the defined length. proc contents noprint data= gui_lib.alert_summary out= column_metadata ; run; but somewhere in that table i need the max length value of that variable: max(length(variable)) – thepen Aug 02 '17 at 19:24
-
sorry first time submitting to stack overflow... :) newbie here – thepen Aug 02 '17 at 19:26
1 Answers
0
To find the maximum length of a EVERY variable in a dataset you will probably need to either transpose the data or generate code.
If you have a unique identifier for each observation then you could first transpose the data and then find the max length.
proc transpose data=have out=tall ;
by rowid ;
var _character_;
run;
proc sql ;
create table want as
select _name_,max(length(col1)) as max_length
from tall
group by 1
;
quit;
Or generate the code to find the max lengths in a single observation and then transpose that. So if your variables are GENDER and RACE you could run this.
proc sql ;
create table wide as
select max(length(GENDER)) as GENDER
, max(length(RACE)) as RACE
from have
;
quit;
proc transpose data=wide out=want;
run;
You could use PROC CONTENTS information on the original data to generate the series of MAX(LENGTH(var)) as var
expressions in that select statement.

Tom
- 47,574
- 2
- 16
- 29