Help using Base SAS procedures

Merging files of multiple lengths

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

Merging files of multiple lengths

I am needing to merge several file that contain the same survey questions. My issue is that the questions are different lengths in each of the datasets.

Is there any way in SAS to specify to ignore length of the variables when merging? Thank you for any assistance you can provide.

HyunJee


Accepted Solutions
Solution
‎11-30-2011 01:55 PM
Super User
Posts: 11,338

Merging files of multiple lengths

By length here I suspect you are referring to text length of responses. I would try specifying the lengths of any common variables before the Merge or Set statement. IF the variables are the same name you probably want to SET instead of MERGE or you'll only get one. If the variables aren't the same name there is no problem.

Data new;

     length TextVar1 TextVar2   $ 200;

     set Data1 Data2;

etc.

View solution in original post


All Replies
Solution
‎11-30-2011 01:55 PM
Super User
Posts: 11,338

Merging files of multiple lengths

By length here I suspect you are referring to text length of responses. I would try specifying the lengths of any common variables before the Merge or Set statement. IF the variables are the same name you probably want to SET instead of MERGE or you'll only get one. If the variables aren't the same name there is no problem.

Data new;

     length TextVar1 TextVar2   $ 200;

     set Data1 Data2;

etc.

PROC Star
Posts: 7,467

Merging files of multiple lengths

If you have 9.2 or newer you could use

options varlenchk=nowarn;

Trusted Advisor
Posts: 2,115

Merging files of multiple lengths

Ignore?  If you don't mind losing some data, then Art's comment on varlenchk will do it.

The default is to set the LENGTH of the output variable to be the same as the length of the first occurrence of that variable across all the datasets (this works for either SET or MERGE).   See http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a001107839.htm .

If you know that one dataset has the lengths of the variables that you want for output, you can specify that first in the list.

You have the most control by using ballardw's approach of explicitly setting the lengths.

Doc Muhlbaier

Duke

PROC Star
Posts: 7,467

Merging files of multiple lengths

Doc,

I have to rephrase your initial statement.  If you risk losing any data then my suggestion should NOT be used.

But, seriously, there are so many times when that risk simply doesn't exist.  Our overused sashelp.class provides a perfect example.  Would it make any difference to merge a file, on name, if a 2nd file only has a length of 7?  No!  The longest name in the file only has seven characters while the length is 8.

Similarly, would one lose any data merging that same file on, say, height or weight, if the other file had different lengths?  Miy point is simply that it is more important to know your data than it is to make sure that the variable lengths are the same.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 776 views
  • 3 likes
  • 4 in conversation