Data Truncated
***************************************************************************************
Hello SAS Communities,
I am in the process of creating and restructuring a data set and I am running into trouble with the SSN variable length as well as the formatting length of the numeric variables being automatically set to BEST12. When I initially create the data set the length of the SSN number is $11, however when I move on to restructuring the data set, the length changes to $9. I am unsure why this is happening. Any feedback is appreciated.
Any information on how to get my SSN length to stay at $11 after restructuring the data and how to get rid of the BEST12. format would be great.
Thank you,
De'Janae'
Please ignore the "Data Truncated" portion at the beginning.
Since you actually have at least 5 data sets involved the most likely culprit is one or more of the contributing data sets on the SET statement have different properties. Does your log show any message like:
WARNING: Multiple lengths were specified for the variable SSN (or any other variable) by
input data set(s). This can cause truncation of data. ?
If so, likely one of the sets that appears earlier in the list has a length of 9.
For brief example:
1 data one; 2 x = 'Some characters'; 3 run; 4 5 data two; 6 x = 'Is a somewhat longer string'; 7 run; 8 9 data combined; 10 set one two; 11 run; WARNING: Multiple lengths were specified for the variable x by input data set(s). This can cause truncation of data. NOTE: There were 1 observations read from the data set WORK.ONE. NOTE: There were 1 observations read from the data set WORK.TWO. NOTE: The data set WORK.COMBINED has 2 observations and 1 variables.
The most common actual cause is relying on Proc Import, often coupled with a spreadsheet source file. Proc Import will set properties for variables after "examining" a very small number of rows of data. If one file is imported and the longest value in the first few rows is 9, that is what you get, another may have 11.
Worse, with spreadsheets since there isn't any contents restriction you can have mixed character and numeric values in a column so values that should be numeric become character. If the spreadsheet were to have multiple rows of header information then 2nd and subsequent header information is treated as data and complicates things.
If you type "excel import length" into the search bar on the Programming page in this forum you will get around 470 results. Most of them involve issues like yours.
Personally if the concern only involves SSN I would leave it as numeric and just apply the SAS supplied SSN format to the values.
data example; input x; format x ssn.; datalines; 123 123456789 ; proc print data=example; run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.