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?
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;
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;
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.
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!
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.