I have a dataset and want to merge with another dataset but i have different lengths for variables in both the datasets.
In this case i am using length statement to match the lenghts but i get warnings.
data ae010;
length AESPID $10 AESTDTC AEENDTC $20 AESEV $50 AECONTRT aeser $1;
set ae010;
run;
WARNING: Multiple lengths were specified for the variable AESPID by input data set(s). This can
cause truncation of data.
WARNING: Multiple lengths were specified for the variable AESEV by input data set(s). This can
cause truncation of data.
WARNING: Multiple lengths were specified for the variable AESER by input data set(s). This can
cause truncation of data.
WARNING: Multiple lengths were specified for the variable AECONTRT by input data set(s). This
can cause truncation of data.
WARNING: Multiple lengths were specified for the variable AESTDTC by input data set(s). This
can cause truncation of data.
WARNING: Multiple lengths were specified for the variable AEENDTC by input data set(s). This
This is perfectly normal behaviour. SAS warns you that data may be lost due to truncation.
You might try to use
options VARLENCHK = NOWARN;
before you run the data step.
Take care to reset the option immediately after the step, as these warnings are there for a purpose.
I can't really tell from what you posted there, perhaps some sample test data of both datasets - in the form of a datastep would help explain. Some thoughts, you can alter length of variables using the proc datasets statement - probably easiest. You can also SQL join the two datasets as that should take the longest length:
proc sql; create table WANT as select coalesce(A.ID,B.ID) as ID length=200 from HAVEA A full join HAVEB B on A.ID=B.ID; quit;
in the output i get the length which i changed but i am still getting the warning message.
This is perfectly normal behaviour. SAS warns you that data may be lost due to truncation.
You might try to use
options VARLENCHK = NOWARN;
before you run the data step.
Take care to reset the option immediately after the step, as these warnings are there for a purpose.
Well, its up to you what you mark the answer, I would however point out here that all you are doing is hiding the problem and that it might come back to haunt you later on, say when you document ends up on someones desk and half the data has been truncated out. Its never a good idea to hide problems.
I can only second @RW9's advice. Make your data clean, have strict structures defined, and you won't have such problems. And if you have them, you know that something is wrong with your input data.
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.
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.