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

Hi ,

 

For one of column the length we are getting from the source is char 300 and but output target has char 30 and we have no control over the source and target. can we use any function like trim or something to get this work ?

 

source (column char 300) --> transformation(function?)  --> target (column char 30) 

 

Thanks

Kajal

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

If your import is done with a datastep :

 

data myNewDataset;
length mySourceVar $30;
set mySource;
run;

if done via SQL:

 

proc sql;
create table myNewDataset as
select
    myId,
    /* other variables */,
    mySourceVar length=30
from mySource;
quit;

With both methods, the variable (mySourceVar) will be truncated by SAS.

PG

View solution in original post

6 REPLIES 6
ballardw
Super User

@kajal_30 wrote:

Hi ,

 

For one of column the length we are getting from the source is char 300 and but output target has char 30 and we have no control over the source and target. can we use any function like trim or something to get this work ?

 

source (column char 300) --> transformation(function?)  --> target (column char 30) 

 

Thanks

Kajal


What is the 'source'? A text file, SAS data set, remote DBMS table?

What kind of "transformation" are you expecting?

 

If I am told the output is limited to 30 characters I need some sort of idea what should be kept and what the starting values may be plus the rules involved in getting the output.

 

If the desired behavior is to just accept the first 30 characters from the source then read the data that way. Or send to the target that as length 30. But kind of need to know how either step is performed to provide concrete examples.

kajal_30
Quartz | Level 8

I have a source where there is a column name with length 300 when I am passing this column to the next transformation it gives me a warning saying that length of column name is less in target and there may a truncation happen 

LinusH
Tourmaline | Level 20

You need to add a derived mapping/calculation, like substr(left(source_column),1,30))

Data never sleeps
ballardw
Super User

@kajal_30 wrote:

I have a source where there is a column name with length 300 when I am passing this column to the next transformation it gives me a warning saying that length of column name is less in target and there may a truncation happen 


So show the code you are using to "pass this column to the next transformation".

 

AND you still have not described what you want to keep from the long string.

There is no way that a 300 character value will fit into a 30 column output. None. So you have to decide what you want and specify that as what goes into the 30 columns if you do not want random truncation notes.

PGStats
Opal | Level 21

If your import is done with a datastep :

 

data myNewDataset;
length mySourceVar $30;
set mySource;
run;

if done via SQL:

 

proc sql;
create table myNewDataset as
select
    myId,
    /* other variables */,
    mySourceVar length=30
from mySource;
quit;

With both methods, the variable (mySourceVar) will be truncated by SAS.

PG

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 2318 views
  • 1 like
  • 4 in conversation