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

I am combining two dataset and some of the subjs email address "in the observation"  is cutting off when I combine the data. I increased the length but, its not helping at all. the email are all fine before combining the data but, when I combine they are cutting of.  

Here is an example of the code I used. 

data need

length email $50;

set data1 and data2;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

That is a way to set the length of a variable (once you fix the typos). Whether it increases the length or not depends on how it was defined before in DATA1.  50 bytes does not seem long enough for an email address.

Note that if it is already truncated in either DATA1 or DATA2 you cannot recover the lost value by just making the variable long. 🙂 

But you also need to watch out if either DATA1 or DATA2 has a format attached to the variable it might be truncating the printing of the values.  There is no good reason to have a $ format attached to a character variable so remove it just in case.

data need ;
  length email $200;
  set data1 data2;
  format email ;
run;

View solution in original post

5 REPLIES 5
hjjijkkl
Pyrite | Level 9
How can I fi this issue
Tom
Super User Tom
Super User

That is a way to set the length of a variable (once you fix the typos). Whether it increases the length or not depends on how it was defined before in DATA1.  50 bytes does not seem long enough for an email address.

Note that if it is already truncated in either DATA1 or DATA2 you cannot recover the lost value by just making the variable long. 🙂 

But you also need to watch out if either DATA1 or DATA2 has a format attached to the variable it might be truncating the printing of the values.  There is no good reason to have a $ format attached to a character variable so remove it just in case.

data need ;
  length email $200;
  set data1 data2;
  format email ;
run;
Reeza
Super User
Your code is wrong as shown, assuming you remove the AND it should likely work fine. Make sure 50 is enough and verify that it wasn't truncated before hand as well.
Patrick
Opal | Level 21

If the issue is really that you've got a same named character variable in your two source tables but the lengths of the variable differ then one way to go in case both data sets have the exactly same variables.

proc sql;
  create table need as
  select * from data1
  union corr all
  select * from data2
  ;
quit;

A SQL UNION CORR ALL will use the max. variable lengths from the source tables to create target table need.

 

If you know exactly in which one of the source tables the variable has a greater length then use this source table first in your set statement. SAS creates the variables in the pdv using the first occurrence of the variable in the code. So if your variable has a greater length in data2 then your code could look like:

data need
  set data2 data1;
run;

 

Or then as you've done in your code set the length of the variable prior to the set statements. That works the same as above as this way the SAS compiler will encounter the variable the first time in the length statement and use this definition to create the variable in the pdv.

data need
  length email $50;
  set data1 data2;
run;

 

 

Ksharp
Super User

Try SQL.

 

data have;
 set sashelp.class;
run;


proc sql;
alter table have
modify sex char(20),name char(100);
quit;

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 2843 views
  • 3 likes
  • 5 in conversation