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

I want to combine a number of datasets and each dataset contains a variable with the name of that dataset for every observations (no missing values).
No matter what I do the variable gets truncated in the combined dataset.

I have tried increasing the length to 100 in each dataset before joining them.
I have tried setting length again before the set statement in a data step.
I have tried joining the tables using outer union corr in proc sql.

Can anyone help me work out why this variable still gets truncated?

 

Example code:  


data want; 
length str $100.; 

set a b c; 

run;

 

proc sql ;

create table want as 

select * from a 

outer union corr

select * from b 

outer union corr 

select * from c 

outer union corr 

;quit; 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Once the values have been truncated, you won't get them back. Anything that is present in the datasets will show up in the result (up to the newly defined length of 100).

Caution must be taken with the presence of formats in the incoming datasets. Make sure that no format is assigned to the variable.

data want; 
length str $100; 
set a b c; 
format str;
run;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

Once the values have been truncated, you won't get them back. Anything that is present in the datasets will show up in the result (up to the newly defined length of 100).

Caution must be taken with the presence of formats in the incoming datasets. Make sure that no format is assigned to the variable.

data want; 
length str $100; 
set a b c; 
format str;
run;
GraphGuy
Meteorite | Level 14

If you're allowed to modify the original datasets, something like this might work ...

 

data a; 
length str $100.; 

set a; 

run;

 

data b; 
length str $100.; 

set b; 

run;

 

data c; 
length str $100.; 

set c; 

run;

 

proc sql ;

create table want as 

select * from a 

outer union corr

select * from b 

outer union corr 

select * from c 

outer union corr 

;quit; 

HenF
Calcite | Level 5

The datasets all had sufficient lengths for that variable, the problem was caused by formats. 

Removing them solved the problem.

HenF
Calcite | Level 5
The problem was caused by formats, but thanks!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4144 views
  • 1 like
  • 3 in conversation