DATA Step, Macro, Functions and more

WARNING: Multiple lengths were specified

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

WARNING: Multiple lengths were specified

[ Edited ]

data new;

input name $;

datalines;

RET_AKT

RET_HIS

RET_AKT

RET_AKT

AMU_NEW

AMU_OLD

;

run;

 

 

data new1;

if name='RET_AKT' then do;

set new;

where name='RET_AKT';

end;

else if name='' then do;

set new;

end;

run;

 

WARNING: Multiple lengths were specified for the variable name by input data set(s). This may

         cause truncation of data.

NOTE: There were 3 observations read from the data set WORK.NEW.

      WHERE name='RET_AKT';

NOTE: There were 1 observations read from the data set WORK.NEW.

NOTE: The data set WORK.NEW1 has 4 observations and 1 variables.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

 

Question . why it is showing 4 obeservation in output dataset  new1  not 3 observation. I want 3 observation in the  dataset new1.why warning is coming 


Accepted Solutions
Solution
‎01-06-2017 01:02 AM
Super User
Posts: 5,080

Re: WARNING: Multiple lengths were specified

To answer your original question, why do you get 4 observations ...

 

As the DATA step begins, NAME is missing.  Therefore, the first SET statement is skipped, and the second one executes.  It reads the first observation from NEW (changing NAME to "RET_AKT") which becomes the first observation in NEW1.

 

From that point forward, NAME is always "RET_AKT". 

 

Therefore, for the rest of the DATA step, the first SET statement executes.  Each SET statement is independent of the other, so the first SET statement begins at the start of NEW and (one at a time) reads in three observations.  Those become the 2nd through 4th observations in NEW1.

 

It would be easier for you to see this if you were to add another variable.  For example, in the creation of NEW, add:

 

obsno = _n_;

 

Then you could look at OBSNO to see where the observations in NEW1 are coming from.

 

View solution in original post


All Replies
Super User
Posts: 5,256

Re: BASE SAS

What are you trying to achieve?

Data never sleeps
Contributor
Posts: 35

Re: BASE SAS

I will create a macro variable which will have column 'name' value or it will be blank

for ex
let x =RET_AKT;

 

After that I want to create a dataset which will take this macro variable value and compare this macro variable value with the column 'name' if value is equal then it will create the dataset 'NEW1' with where name=&x and if value of macro variable is blank then it will copy all the records from dataset 'new' to dataset 'new1'

for ex

if let x=RET_AKT; then it will copy 3 records from dataset new to dataset new1

and if let x=; then it should copy 6 records to dataset new 1

 

Hope I able to explain

Contributor
Posts: 35

Re: BASE SAS

data new;
input name $;
datalines;
RET_AKT
RET_HIS
RET_AKT
RET_AKT
AMU_NEW
AMU_OLD
;
run;

%let x=RET_AKT;

data new1;
if name="&X" then do;
set new;
where name="&X";
output;
end;
else if name='' then do;
set new;
output;
end;
run;

why it is showing 4 rows in the output
Contributor
Posts: 52

Re: WARNING: Multiple lengths were specified

Hey,

 

If i understood the question correctly, you want to filter out the data based on the name value of- 'RET_AKT'.

You are doing the logic incorrectly, 

 


data new;
input name $;
datalines;
RET_AKT
RET_HIS
RET_AKT
RET_AKT
AMU_NEW
AMU_OLD
;
run;
 
 
data new1;
set new;
where name='RET_AKT';
run;

the warning is coming, because when you created the dataset new, the default length of 8 byte is assigned . However when you created the datset new1, you didn't assign the length, so it took the length from the first assignement of name variable, ie. from 

if name='RET_AKT' then do; which will only have a length of 7 bytes.

 

WARNING: Multiple lengths were specified for the variable name by input data set(s). This may

         cause truncation of data.

 

Hoep this helps!

 

Manjeet


Cheers from India!

Manjeet
Contributor
Posts: 24

Re: WARNING: Multiple lengths were specified

[ Edited ]

Small correction to @mnjtrana solution.

 

%let X=RET_AKT;

data
new1; set new; where NAME="&X" or "&X" = ''; run;

 

So,  if NAME=X then dataset is filtered else X='' then all obs are kept.

 

Hope it helps.

 

Daniel Santos @ www.cgd.pt

Solution
‎01-06-2017 01:02 AM
Super User
Posts: 5,080

Re: WARNING: Multiple lengths were specified

To answer your original question, why do you get 4 observations ...

 

As the DATA step begins, NAME is missing.  Therefore, the first SET statement is skipped, and the second one executes.  It reads the first observation from NEW (changing NAME to "RET_AKT") which becomes the first observation in NEW1.

 

From that point forward, NAME is always "RET_AKT". 

 

Therefore, for the rest of the DATA step, the first SET statement executes.  Each SET statement is independent of the other, so the first SET statement begins at the start of NEW and (one at a time) reads in three observations.  Those become the 2nd through 4th observations in NEW1.

 

It would be easier for you to see this if you were to add another variable.  For example, in the creation of NEW, add:

 

obsno = _n_;

 

Then you could look at OBSNO to see where the observations in NEW1 are coming from.

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 900 views
  • 1 like
  • 5 in conversation