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

Dear friends,

 

I have many tables connected to a LOOKUP transformation. There is a character variable (let's call it X) which has different length in the tables. I want all of them be finally $5.

 

I wrote:

 

put(X , $5.)

 

in the EXPRESSION for the variable X in the LOOKUP transformation but it didn't solve the problem.

 

Do you know how I can solve this?

 

Best regards

 

Farshid Owrang

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

The expression gets used for the target table and not for source tables.

 

Implementing ETL processes using DIS the same named variable should always mean the same and have the same attributes in all tables so best way would be to fix the source problem. You can use Tool/Standardize Columns for this task. Once metadata is fixed you also need to re-create permanent physical tables for such changes to take effect. And you need to redeploy all DIS jobs using any of the tables with changed metadata.

 

The Lookup Transformation doesn't let you change input variable attributes. If it isn't possible for you to fix the source problem then one way to go is to add a SQL Extract node where you create the variable as required, define the target as view and then use this view as input to the Lookup Transformation.

 

View solution in original post

6 REPLIES 6
RichardDeVen
Barite | Level 11

Is the issue that the X column is longer or shorter than $5 ?

 

Specify the variable length prior to a SET statement that reads a table with a column named X, or before any other computation that might implicitly set the variables length.  By doing so, the code forces the variable length, not side effects.

data want;
  length x $5;
...
* set statement;
* formula statement;
run;
farshidowrang
Quartz | Level 8
Thank you very much my friend!
ChrisNZ
Tourmaline | Level 20

Is this a data step? I assume so since this message is not displayed by SQL afaik.

If you set the length to 5, and some of the variables (not the values, SAS does not check the values) are longer than 5, th message is displayed because the variables with a length greater than 5 might be truncated to 5, and therefore lose data.

 

Running

X=put(X,$5.);

does not reset the length of the variable, only the length of the value.

 

Running

Y=put(X,$5.);

drop X;

rename Y=X;

should do what you want.

 

 

 

Patrick
Opal | Level 21

The expression gets used for the target table and not for source tables.

 

Implementing ETL processes using DIS the same named variable should always mean the same and have the same attributes in all tables so best way would be to fix the source problem. You can use Tool/Standardize Columns for this task. Once metadata is fixed you also need to re-create permanent physical tables for such changes to take effect. And you need to redeploy all DIS jobs using any of the tables with changed metadata.

 

The Lookup Transformation doesn't let you change input variable attributes. If it isn't possible for you to fix the source problem then one way to go is to add a SQL Extract node where you create the variable as required, define the target as view and then use this view as input to the Lookup Transformation.

 

farshidowrang
Quartz | Level 8
Perfect!

Thank you very much!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 529 views
  • 0 likes
  • 4 in conversation