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
Rhodochrosite | Level 12

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-2024.png

📢

ANNOUNCEMENT

The early bird rate has been extended! Register by March 18 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 488 views
  • 1 like
  • 3 in conversation