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

Hi

 

I am trying to run linear discriminant analysis on my data but  I am running into this error and I am not sure on how I need fix my data to overcome the error. I am going to attach my raw data:PARKDAT here (80 obs) and my test data:newdata (16 obs). (I am using the most recent version of SAS Studio) This is the code I ran:

 

Proc Discrim Data=PARKDAT Method=Normal testdata=newdata Pool=Yes

pcov listerr crosslisterr Crossvalidate testlist;
Class Status;
Var _NUMERIC_;
Priors Prop;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Have you confirmed that it is the course of the problem?

 

The best way to fix it is when you import the data. You haven't stated how you read the data into SAS, so I can't say more.

 

You can also fix it after importing by using the LENGTH statement. For example,

data NewData2;

length Status $13;

set NewData;

run;

View solution in original post

5 REPLIES 5
Rick_SAS
SAS Super FREQ

It is always best to paste the EXACT error message from the SAS log.

 

I am going to guess that the length of the Status variable in the PARKDAT data set is different than the length of the same variable in the NEWDATA data set.  You can use PROC CONTENTS to examine the lengths.

wkm21
Calcite | Level 5

Hi Rick

Typically how do you go about fixing that?

Rick_SAS
SAS Super FREQ

Have you confirmed that it is the course of the problem?

 

The best way to fix it is when you import the data. You haven't stated how you read the data into SAS, so I can't say more.

 

You can also fix it after importing by using the LENGTH statement. For example,

data NewData2;

length Status $13;

set NewData;

run;

wkm21
Calcite | Level 5
Hi Rick

Yes the error that you predicted is correct :

ERROR: The TESTCLASS variable must have the same length as the CLASS variable.
NOTE: The SAS System stopped processing this step because of errors.

When I import the data this how wrote the code:

FILENAME REFFILE '/home/wkmustahs210/sasuser.v94/testdataParkDAT.csv';

PROC IMPORT DATAFILE=REFFILE
DBMS=CSV
OUT=newdata;
GETNAMES=YES;
RUN;

PROC CONTENTS DATA=newdata; RUN;


I used the upload and import function on SAS. I have question about "NewData2". So I run that code and I want to use the NewData2 for LDA analysis will the code be something like this:

Title2 'Linear Discriminant Analysis';
Proc Discrim Data=PARKDAT Method=Normal testdata=NewData2 Pool=Yes
pcov listerr crosslisterr Crossvalidate testlist;
Class Status;
Var _NUMERIC_;
Priors Prop;

Run;
Are there any additional modifications I have to make

Thanks,
Rose
Rick_SAS
SAS Super FREQ

By default, PROC IMPORT looks at the first 20 rows to guess things like length and format, so you can try to add

	guessingrows=max;

before your RUN statement.

 

As you probably know, for delimited files PROC IMPORT is just a front end to a DATA step. You can see the DATA step code in the log. If you want, you can copy the code and add a LENGTH statement.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 977 views
  • 2 likes
  • 2 in conversation