Solved
New Contributor
Posts: 4

# What am I doing Wrong

I am trying to run a simple Anova procedure. Could anyone tell me by looking at the below code what am I doing wrong? I need to get some type of output data beside just listing the dollar amount to the number next to it.

DATA ONE; FIRSTOBS=2 DLM='09'X
INPUT FREQ \$ LOC;
Cards;
\$36,198 1
\$44,166 4
\$31,874 4
\$32,691 1
\$41,259 4
\$32,126 4
\$42,924 2
\$39,338 2
\$35,166 1
\$33,664 1
\$41,027 4
\$31,159 4
\$37,166 3
\$34,696 3
\$33,226 3
\$33,386 3
\$35,166 1
\$38,655 1
\$31,835 2
\$43,235 2
\$40,600 2
\$35,901 3
\$34,505 3
\$31,184 1
\$30,064 3
\$27,274 4
\$30,844 3
\$35,358 4
\$34,280 2
\$48,631 2
\$31,960 4
\$43,839 2
\$30,778 1
\$32,019 3
\$33,096 3
\$31,606 3
\$33,549 4
\$41,901 2
\$39,196 2
\$32,306 1
\$29,851 3
\$34,098 1
\$38,091 3
\$33,081 4
\$35,541 2
\$37,848 1
\$36,335 4
\$32,533 1
\$33,546 3
\$43,269 4

INPUT FREQ LOC;
IF LOC=1 THEN REGION='Southeast';
IF LOC=2 THEN REGION='Northeast';
IF LOC=3 THEN REGION='Midwest';
IF LOC=4 THEN REGION='WEST';
RUN;
PROC PRINT;
RUN;
PROC ANOVA;
CLASS REGION;
MODEL MEDINC=REGION;
MEANS REGION/SCHEFFE TUKEY LSD SNK ALPHA=0.05;
RUN;
*/PROC GLM;
*CLASS REGION;
*MODEL FREQ=REGION;
*CONTRAST 'CENTRAL CITY VS. SUBURBS AND RURAL' REGION -1 0.5 0.5;
*MEANS REGION/SCHEFFE TUKEY LSD SNK ALPHA=0.1;
*RUN;
/*PROC NPAR1WAY ANOVA WILCOXON;
CLASS REGION;
VAR FREQ;
RUN;*/

Accepted Solutions
Solution
‎04-24-2018 09:47 AM
New Contributor
Posts: 4

## Re: What am I doing Wrong

Thank you! The one that you did worked for me also. I am also attempting to do this code with the same one.

/PROC GLM;
CLASS REGION;
MODEL FREQ=REGION;
CONTRAST 'CENTRAL CITY VS. SUBURBS AND RURAL' REGION -1 0.5 0.5;
MEANS REGION/SCHEFFE TUKEY LSD SNK ALPHA=0.1;
RUN;
PROC NPAR1WAY ANOVA WILCOXON;
CLASS REGION;
VAR FREQ;
RUN;

It is also not working. I really appreciate your help as I am beyond a SAS novice!

All Replies
Super User
Posts: 6,751

## Re: What am I doing Wrong

[ Edited ]

First, let's clean up the DATA step in a few ways.  Abbreviating the data lines for readability (you wouldn't actually do that), here is an improved version:

DATA ONE;

informat FREQ dollar8.;
INPUT FREQ LOC;

IF LOC=1 THEN REGION='Southeast';
else IF LOC=2 THEN REGION='Northeast';
else IF LOC=3 THEN REGION='Midwest';
else IF LOC=4 THEN REGION='WEST';
Cards;
\$38,655 1
\$31,835 2
\$43,235 2
\$40,600 2
\$35,901 3
\$34,505 3

;

This version makes FREQ a numeric variable instead of character.

In the ANOVA, one thing stands out as possibly being a problem.  In a MEANS statement, are you permitted to use a character variable?  (I actually don't know the answer to that.)  Instead of using REGION, you could certainly use LOC (in all three places).

PROC ANOVA;
CLASS REGION;
MODEL MEDINC=REGION;
MEANS REGION/SCHEFFE TUKEY LSD SNK ALPHA=0.05;
RUN;

New Contributor
Posts: 4

## Re: What am I doing Wrong

Thanks for the help but it is still not wanting to run the ANOVA

Super User
Posts: 6,751

## Re: What am I doing Wrong

You'll have to help out here.  Post the log, so we can see what is not working.

PROC Star
Posts: 8,163

## Re: What am I doing Wrong

The following works for me:

```DATA ONE;
infile cards DLM='09'X;
INPUT medinc comma7. LOC;
IF LOC=1 THEN REGION='Southeast';
else IF LOC=2 THEN REGION='Northeast';
else IF LOC=3 THEN REGION='Midwest';
else IF LOC=4 THEN REGION='WEST';
Cards;
\$36,198 1
\$44,166 4
\$31,874 4
\$32,691 1
\$41,259 4
\$32,126 4
\$42,924 2
\$39,338 2
\$35,166 1
\$33,664 1
\$41,027 4
\$31,159 4
\$37,166 3
\$34,696 3
\$33,226 3
\$33,386 3
\$35,166 1
\$38,655 1
\$31,835 2
\$43,235 2
\$40,600 2
\$35,901 3
\$34,505 3
\$31,184 1
\$30,064 3
\$27,274 4
\$30,844 3
\$35,358 4
\$34,280 2
\$48,631 2
\$31,960 4
\$43,839 2
\$30,778 1
\$32,019 3
\$33,096 3
\$31,606 3
\$33,549 4
\$41,901 2
\$39,196 2
\$32,306 1
\$29,851 3
\$34,098 1
\$38,091 3
\$33,081 4
\$35,541 2
\$37,848 1
\$36,335 4
\$32,533 1
\$33,546 3
\$43,269 4
;

PROC ANOVA;
CLASS REGION;
MODEL MEDINC=REGION;
MEANS REGION/SCHEFFE TUKEY LSD SNK ALPHA=0.05;
RUN;
```

Art, CEO, AnalystFinder.com

Solution
‎04-24-2018 09:47 AM
New Contributor
Posts: 4

## Re: What am I doing Wrong

Thank you! The one that you did worked for me also. I am also attempting to do this code with the same one.

/PROC GLM;
CLASS REGION;
MODEL FREQ=REGION;
CONTRAST 'CENTRAL CITY VS. SUBURBS AND RURAL' REGION -1 0.5 0.5;
MEANS REGION/SCHEFFE TUKEY LSD SNK ALPHA=0.1;
RUN;
PROC NPAR1WAY ANOVA WILCOXON;
CLASS REGION;
VAR FREQ;
RUN;

It is also not working. I really appreciate your help as I am beyond a SAS novice!

PROC Star
Posts: 8,163

## Re: What am I doing Wrong

Like with your original code, you refer to a variable called FREQ, but don't have any such variable in your dataset. I presume that you were trying to run:

```PROC GLM data=one;;
CLASS REGION;
MODEL MEDINC=REGION;
CONTRAST 'CENTRAL CITY VS. SUBURBS AND RURAL' REGION -1 0.5 0.5;
MEANS REGION/SCHEFFE TUKEY LSD SNK ALPHA=0.1;
RUN;

PROC NPAR1WAY data=one ANOVA WILCOXON;
CLASS REGION;
VAR MEDINC;
RUN;
```

Art, CEO, AnalystFinder.com

New Contributor
Posts: 4

## Re: What am I doing Wrong

Art,

Just wanted to say thank you for your help. It was very much appreciated.

☑ This topic is solved.