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

I have a data set that summarizes several hundred candidate models and one field is "Vars_in_model" and another is "Variable."

 

Upon declaration, I do data out Data; length Variable $27; length Variables_in_model $800; run;

 

That works, but when the data set is updated with the component macros, somehow the "Variable" gets set to size 16 and variables_in_model get set to $57. It is clearly setting it to the shortest. I have unchecked the options in SAS Eg, and re checked and re run and get the same result.

What is odd to me is I even take the output data set and try to resize with the same statements and it still stays the same size. I am doing a work around where I start with the largest first so it gets set with the largest, but this seems odd to me. Any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

When you use more than one dataset in a set statement, and the datasets contain common variables, the attributes are set from the first dataset named in the set that contains a given variable. If subsequent datasets contain the same variable with a bigger length, the values from that are truncated, and you get a WARNING about that in the log.

Make sure that a certain variable is always created with the same length in all your datasets. This gives you a clean log and avoids confusion.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

When you use more than one dataset in a set statement, and the datasets contain common variables, the attributes are set from the first dataset named in the set that contains a given variable. If subsequent datasets contain the same variable with a bigger length, the values from that are truncated, and you get a WARNING about that in the log.

Make sure that a certain variable is always created with the same length in all your datasets. This gives you a clean log and avoids confusion.

Tom
Super User Tom
Super User

You need to show exactly what you did as SAS will set the length for the variable at the first point it can.

So if the LENGTH statement comes after a SET statement for a dataset that already has that variable the LENGTH statement is ignored.

Also watch out for FORMATs that might be attached to character variables.  It is best to just remove any formats that might have gotten accidentally attached to character variables.

 

Here is an example for how to create a new dataset with changed variable lengths.

data want ;
  length Variable $27 Variables_in_model $800; 
  set have ;
  format variable variables_in_model ;
run;
stratozyck
Calcite | Level 5

It is fixed by changing the order of the multiple sets. I don't know why that works because both data sets had the same formatting.

Tom
Super User Tom
Super User

@stratozyck wrote:

It is fixed by changing the order of the multiple sets. I don't know why that works because both data sets had the same formatting.


By definition the datasets did not have the same structure if changing the order of the datasets in a SET statement made a difference.

Note that you cannot count on being able to fix this type of issue by just changing the dataset order. What if there is more than one variable with different lengths?  You could have a situation where any order results in one of the variables being truncated.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 914 views
  • 1 like
  • 3 in conversation