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

I have a data step that has the following format: 

data in (keep= x y z);
set have; 
if x='today' and y ='tomorrow'; 
parameter  = ''; 
if var1 = 'Good' then var = 1;
    	else if var1 = 'Bad' then var = 2;
    	else if var = 0; 
var1 = x; run;

When I run this, my var1 output becomes truncated like the following: 

var1    x
  t     today
  y  yesterday 
  e    earlier 
         

I have tried inserting a line to define the length: 

length parameter $20 var1 $50;

But this didn't fix the issue. Is there anyway I can resolve this? 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

They is nothing in that code that would define VAR1 as length $1.  

Does VAR1 already exist in the input dataset, HAVE?

If so it perhaps have a format attached to it?

 

Set the length BEFORE pulling the dataset.  You cannot change the length of character variable after it has already been set.

Then remove any format that might be attached to it.  In fact why not just remove any formats attached to any of your character variables.

data in (keep= x y z);
  length parameter $20 var1 $50;
  set have; 
  ....
  format _character_ ;
run;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

They is nothing in that code that would define VAR1 as length $1.  

Does VAR1 already exist in the input dataset, HAVE?

If so it perhaps have a format attached to it?

 

Set the length BEFORE pulling the dataset.  You cannot change the length of character variable after it has already been set.

Then remove any format that might be attached to it.  In fact why not just remove any formats attached to any of your character variables.

data in (keep= x y z);
  length parameter $20 var1 $50;
  set have; 
  ....
  format _character_ ;
run;
serena13lee
Quartz | Level 8
Thanks! That was exactly what I needed.
Kurt_Bremser
Super User

Lines 2 and 3 can NOT have come from your code, as you have a subsetting if on x = "today".

Please show an example for dataset have, the code you actually ran and the result from that specific run.

serena13lee
Quartz | Level 8
Thanks! Sorry for the theoretical approach. It appears that changing the area of where I added length was sufficient in resolving my issue. I will add a 'have' dataset in the future.

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
  • 4279 views
  • 0 likes
  • 3 in conversation