BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HyunJee
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
ballardw
Super User

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.

art297
Opal | Level 21

If you have 9.2 or newer you could use

options varlenchk=nowarn;

Doc_Duke
Rhodochrosite | Level 12

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

art297
Opal | Level 21

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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