DATA Step, Macro, Functions and more

How to avoid truncation of the data?

Reply
Occasional Contributor
Posts: 10

How to avoid truncation of the data?

Hi guys,

 

How can I avoid the truncation of the data in the data steps(merge the datasets) of the loop?

 

The warnings show:

 

WARNING: Multiple lengths were specified for the variable "....." by input data set(s). This can cause truncation of data.

 

The code is:

 

data raj.brfssfinal;

set raj.brfss11 raj.brfss12 raj.brfss13 raj.brfss14
raj.brfss15 raj.brfss16;
run;

 

Out of all those datasets, only brfss16 has a variable seqno which is a character variable and therefore, it gives me an error: ERROR: Variable seqno has been defined as both character and numeric!! 

 

When I change the character variable in the raj.brfss16 dataset to numerical variable, then it gives me trauncation error for multiple other variable except seqno. I am not sure where am I going wrong.

 

Please help me out with this.

 

Thanks! 

Super User
Posts: 10,278

Re: How to avoid truncation of the data?

Posted in reply to raajdesaii

If you get those datasets from external sources, you need to correct all this in the steps that read the data, and your issues will disappear on their own.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 10

Re: How to avoid truncation of the data?

Posted in reply to KurtBremser

So by that do you mean convert the variables to either numeric or character in the steps that read the data? 

 

I tried doing that and it still would not work. 

Super User
Posts: 10,278

Re: How to avoid truncation of the data?

Posted in reply to raajdesaii

You don't convert, you correct the input and other statements that set variable attributes. Note that you do NOT use proc import in such situations, you use one data step to read all infiles.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 13,583

Re: How to avoid truncation of the data?

Posted in reply to raajdesaii

To have a variable like SEQNO as both character and numeric means that in at least one program where you read the data you created the variable as character.

 

You might find this bit of code useful for summarizing the characteristics of your variables in the given data sets.

The 1 in the results columns basically serves to indicate which year of your data has the characteristics of the variables that will be the row headers.

Proc tabulate data=sashelp.vcolumn;
   where libname='RAJ' and 
         memname in ('BRFSS11' 'BRFSS12' 'BRFSS13' 'BRFSS14');
   class memname name type length;
   table name*type* length,
         memname
         /misstext=' '
   ;
run;

And depending on how much your organization does with standardizing BRFSS data variables you a very likely to have question numbers from the survey from different years with different ranges of values not just the occasional change from numeric to character caused by your read program(s).

 

 

I have worked with BRFSS data from collection to reporting in a number of roles since 1998 and have used the data back to 1984. So have developed tools, such as the tabulate above, to summarize the metadata.

Ask a Question
Discussion stats
  • 4 replies
  • 67 views
  • 0 likes
  • 3 in conversation