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

I can not figure out what I'm doing wrong. I got an error for location. I posted my log and the code I used. What did I do wrong?


proc glm;
class location(ref="inner suburbs");
model y=x1 location X1*location/solution;
run;

 

Screenshot 2023-10-29 211625.png

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Read in the file properly and the GLM code will properly work.

 

Main thing is define LOCATION to be long enough to actually hold a value that is that long.

 

You are currently telling SAS that LOCATION should be defined as character variable of length 8.

 

Also you really should use the DSD option when reading a delimiter file.  Otherwise missing values can cause the INPUT statement to read from the wrong field on the line.

 

Either define the variables with a LENGTH statement before the INPUT statement (in which case you don't need the $ in the INPUT statement since the variable's type will already be set).

 

Or include an informat in the INPUT statement. But make sure to precede the informat specification with the colon modifier so that it still just reads the next field from the line.

 

Structure your data step like this:

data hw7;
  length house y x1-x4 8 location $20;
  infile "...filename..." dsd dlm='09'x truncover firstobs=2;
  input house -- location;
run;

View solution in original post

3 REPLIES 3
WarrenKuhfeld
Ammonite | Level 13

Run proc contents on your input data set. Run proc freq on your location variable. Is "inner suburbs" really a value? Don't trust what you think or what you see in your instream data. Look at the data set.

Tom
Super User Tom
Super User

Read in the file properly and the GLM code will properly work.

 

Main thing is define LOCATION to be long enough to actually hold a value that is that long.

 

You are currently telling SAS that LOCATION should be defined as character variable of length 8.

 

Also you really should use the DSD option when reading a delimiter file.  Otherwise missing values can cause the INPUT statement to read from the wrong field on the line.

 

Either define the variables with a LENGTH statement before the INPUT statement (in which case you don't need the $ in the INPUT statement since the variable's type will already be set).

 

Or include an informat in the INPUT statement. But make sure to precede the informat specification with the colon modifier so that it still just reads the next field from the line.

 

Structure your data step like this:

data hw7;
  length house y x1-x4 8 location $20;
  infile "...filename..." dsd dlm='09'x truncover firstobs=2;
  input house -- location;
run;
Iamcassandra02
Calcite | Level 5

thank you so much. That worked!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 3 replies
  • 1568 views
  • 1 like
  • 3 in conversation