SAS variable lengths distribution macro

asked 2017-05-12 08:57:59 -0500

Hello, I routinely am reading in data into SAS from various formats and must analyze the data's integrity. It is important for me to set the length of the variable large enough to accommodate the longest variable but knowing the distribution of lengths also goes a long way to informing me of data integrity problems. I am searching for a more efficient, more automated way of looking at the distribution of lengths. I always bring everything over as a character variable. Please see my method below

/***************Setting initial lengths****************************/
/***************Creating number as a character variable************/
data lengths (keep=CLIENT SERVER DESC NUMBER LEN_CLIENT LEN_SERVER LEN_DESC LEN_NUMBER);
length     CLIENT $ 100
           SERVER $ 100
           DESC   $ 100
           NUMBER $ 100;

INFORMAT CLIENT $100. SERVER $100. DESC $100. NUMBER $100. ; SET SASHELP.MONIKER; NUMBER="10"; /*******left-aligning all character strings and determining lengths********/ CLIENT = LEFT (CLIENT ) ; SERVER = LEFT (SERVER ) ; DESC = LEFT (DESC ) ; NUMBER = LEFT (NUMBER ) ; LEN_CLIENT = LENGTH (CLIENT ) * (CLIENT NE " ") ; LEN_SERVER = LENGTH (SERVER ) * (SERVER NE " ") ; LEN_DESC = LENGTH (DESC ) * (DESC NE " ") ; LEN_NUMBER = LENGTH (NUMBER ) * (NUMBER NE " ") ;

/*************************looking at the distribution of lengths*********************************************/
/*************************the distribution of the lengths is equally informative to the max******************/
PROC FREQ   DATA = lengths ;
TABLES      LEN_CLIENT
                    LEN_SERVER
                    LEN_DESC
            LEN_NUMBER
                        ;
RUN;
/**********************Setting the variable to the Max Length**************************************************/
/**********************Creating Number as a numeric variable***************************************************/
DATA WORK.FINAL (KEEP = CLIENT SERVER DESC NUMBER) ;
LENGTH CLIENT   $ 51
             SERVER   $ 30
             DESC        $ 60
             NUMBER    8.
                          ;
SET lengths  (RENAME = (NUMBER    = VAR_A));
         NUMBER  = INPUT (VAR_A,  COMMA2.)      ;
RUN                                                         ;

Typing this all out takes a large part of my day and I am convinced there is a macro that will solve my problem. Thanks in advanced!

edit retag flag offensive close merge delete