BookmarkSubscribeRSS Feed
caveman529
Calcite | Level 5

Dear All:

I have around 50 tables that I hope to combine into one using:

data data_combo;

set data1-data50;

run;

These tables contain common variable names.  But I got the following error message:

Multiple lengths were specified for the variable VARIABLEXXX by input data set(s). This may cause truncation of data.

How could I avoid such problem by just specify in the data_combo, the length of the variable is set as the largest of the all the tables that are going to be combined into DATA_COMBO?  Right now, I have to do a PROC CONTENTS to see the variable length for all of the table and then manually specify the maximum length

6 REPLIES 6
data_null__
Jade | Level 19
/*Sample data*/
data data1 data3;
   length a $10 C $14;
  
stop;
  
call missing(of _all_);
   run;
data data2 data4;
   length a $15 x 8 b $13 c $13;
  
stop;
  
call missing(of _all_);
   run;

/* Collect relevant meta data*/
data info;
   set sashelp.vcolumn(keep=libname memname type name length);
   where libname eq 'WORK' and upcase(memname) eq: 'DATA';
   name = upcase(name);
  
run;

proc summary data=info nway;
  
class name / order=data;
   class type;
   output out=maxl(drop=_: index=(name)) max(length)=;
   run;
proc print;
  
run;

/* Gen some new attrib statements */
filename FT45F001 temp;
data _null_;
  
file FT45F001;
   set maxl;
   put 'Attrib ' name  'length=' @;
   if type eq 'char' then put '$' @;
   put length ';';
  
run;
data new;
   %inc FT45F001;
   set data1-data4;
   run;
proc contents;
  
run;
caveman529
Calcite | Level 5

Suppose that the data are stored in d:\sasdata\ and the libname for it is mydata.  How would I accommodate the code? 

I tried to modify the code into:

where libname eq 'mydata' and upcase(memname) eq: 'DATA';

But it doesn't seem to work...

Linlin
Lapis Lazuli | Level 10

Hi,

change

where libname eq 'mydata' and upcase(memname) eq: 'DATA';

to

where libname eq 'MYDATA' /* has to be upcase */ and upcase(memname) eq: 'DATA';


Message was edited by: Linlin

Haikuo
Onyx | Level 15

Alternatively if go for Proc SQL route:

proc sql;

  select distinct cats(upcase(name),'$', max(LENGTH)) into :len separated by ' ' from dictionary.columns

where LIBNAME='WORK'

AND SUBSTR(MEMNAME,1,4)='DATA'

AND type='char'

group by upcase(name);

QUIT;

data want;

length &len;

set data1-data4;

run;

Haikuo

Update: this only works for Char vars. While I have never seen a different length for Num other than 8 in my real work.

caveman529
Calcite | Level 5

Hi, Hai:

I modify the libname = 'mydata', but the program report:

Syntax error, expecting one of the following: a name, ;, DEFAULT, _ALL_,

              _CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 200-322: The symbol is not recognized and will be ignored

Haikuo
Onyx | Level 15

libname = 'MYDATA', needs CAPS.

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
  • 6 replies
  • 586 views
  • 1 like
  • 4 in conversation