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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 4830 views
  • 0 likes
  • 3 in conversation