BookmarkSubscribeRSS Feed
AJ_Brien
Quartz | Level 8

Hello,

 

I'm running this piece of code, but even though here it says LEAD, in the output it shows up as LEA. Why is the flag value getting cut off?

This is the first instance of the variable flag that SAS encounters, so it's not even that the size of flag is being set before by some other value. Appreciate the help. Thanks!

 

data abc;
set abc;
if stage in ('45','35') then flag="LEAD";
run;
6 REPLIES 6
PGStats
Opal | Level 21

It might be that flag already exists in dataset abc.

 

Add the statement

 

length flag $8;

 

before the set statement.

PG
AJ_Brien
Quartz | Level 8
For some reason that didn't help either. It still displays as LEA.

This flag has not been declared, initialized or used anywhere else before this statement, that's what's confusing me
Tom
Super User Tom
Super User

It is possible that the issues is with a format that is attached to the variable.  Changing the length will not change the format attached. So if you force the length to by 8 bytes but it still has $3 format attached to it then only the first three characters will show on printouts.

AJ_Brien
Quartz | Level 8
This is what the log says at the end of that datastep:

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
2765:4
NOTE: There were 522116 observations read from the data set WORK.ABC.
NOTE: The data set WORK.ABC has 522116 observations and 14 variables.
NOTE: DATA statement used (Total process time):
real time 0.17 seconds
cpu time 0.18 seconds
PGStats
Opal | Level 21

Then try

 

data abc;
set abc(drop=flag);
if stage in (45, 35) then flag="LEAD";
run;
PG
ballardw
Super User

@AJ_Brien wrote:

Hello,

 

I'm running this piece of code, but even though here it says LEAD, in the output it shows up as LEA. Why is the flag value getting cut off?

This is the first instance of the variable flag that SAS encounters, so it's not even that the size of flag is being set before by some other value. Appreciate the help. Thanks!

 

data abc;
set abc;
if stage in ('45','35') then flag="LEAD";
run;

If you ran this code more than once then you do have the variable flag in the data set ABC because you placed it there.

This is a side effect of using the

Data abc;

   set abc;

 

code structure. The first time you ran that code and there were no errors preventing the execution you completely replaced the data set.

If you previously ran the code with a logic error such as:

if stage in ('45','35') then flag="LEA";

then you created a text variable with a length of 3.

 

When testing recoding of variables always send the output to a different data set so you do not corrupt your starting data.

 

Also post your log with code and any messages together into a code box.

 

Something else: define "getting cut off". How are you seeing a "cut off" value? Did you Print the data set (or at least that variable)? Put statement in the data step? Something else?

Have you run Proc contents on the data set to tell you what the properties of the variable Flag might be? Perhaps somehow it acquired a format of $3. limiting what value will display in either a viewtable or printed output.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 839 views
  • 0 likes
  • 4 in conversation