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-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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