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

I have the code below that I am trying to run, but keep getting errors on the where clause. The error is "Syntax error, expecting one of the following: ;, !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, GE, GT,  LE, LT, NE, NOT, OR, ^, ^=, |, ||, ~, ~="  Is there something else I can do to get this to work? I'm new to SAS so I'm open to suggestions if this is possible.

%let DEAN1A = 1; /* Dean of Arts & Sciences Code (1) */

PROC TABULATE

DATA=GRDDIST.&STERM.vpi_secgcat;

    BY DIV;

    WHERE DEAN = &DEAN1A.;

    VAR CAMPUS;

       CLASS grdcat DPT COURSE name_1 SEC3 /    ORDER=UNFORMATTED MISSING;

    CLASSLEV grdcat;

    CLASSLEV DPT / STYLE=[OUTPUTWIDTH=1in];

    CLASSLEV COURSE / STYLE=[OUTPUTWIDTH=.5in];

    CLASSLEV name_1 / STYLE=[OUTPUTWIDTH=2in];

    CLASSLEV SEC3 / STYLE=[OUTPUTWIDTH=.5in];

    TABLE

                 /* ROW Statement */

         DPT={LABEL=""}*COURSE={LABEL=""}*name_1={LABEL=""}*SEC3={LABEL=""},

        /* COLUMN Statement */

        grdcat={LABEL=""} *(CAMPUS={LABEL=""} * N={LABEL="#" S=[CELLWIDTH=.5in]} CAMPUS={LABEL=""}

         * RowPctN={LABEL="%" S=[CELLWIDTH=.5in]}*f=pctfmt.)

        all = 'Total'  *(CAMPUS={LABEL=""} * N={LABEL="#" S=[CELLWIDTH=.5in]} CAMPUS={LABEL=""}

         * RowPctN={LABEL="%" S=[CELLWIDTH=.5in]}*f=pctfmt.)    ;

    ;

RUN; QUIT;

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

The %put DEAN1A suggestion was just to show the value of &DEAN1A, which you've accomplished with turning on SYMBOLGEN, so no need for that now.

The error about where clause requiring compatible variables means what it says (in SAS-speak : )

Your code will become:

  where DEAN = 1;

That would work if DEAN is a numeric variable, but not if DEAN is a character variable.  If DEAN is a character variable, then you could use:

  where DEAN = "1";

So you could change your %LET statement to

  %let DEAN1A = "1";

Or leave your %let statement as is and instead change your WHERE statement to

  where DEAN = "&DEAN1A" ;

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

6 REPLIES 6
Reeza
Super User

What line is generating the error? Can you post the full log?

Quentin
Super User

Yes, please post the full log.

If you are getting that error from the WHERE statement, my guess is you forgot to run the %LET statement  (you should get warning about macro variable DEAN1A not existing), or for some reason the macro variable has a weird value.

Suggest add

  %put DEAN1A = >>&DEAN1A<< ;

Immediately before your tabulate step, and see if the value is what you expect.

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
laura6728
Obsidian | Level 7

Adding   %put DEAN1A = >>&DEAN1A<< ; before my tabulate didn't work. I thought it had, but now i reran it to show a coworker and it populated the same error.

Quentin
Super User

The %put DEAN1A suggestion was just to show the value of &DEAN1A, which you've accomplished with turning on SYMBOLGEN, so no need for that now.

The error about where clause requiring compatible variables means what it says (in SAS-speak : )

Your code will become:

  where DEAN = 1;

That would work if DEAN is a numeric variable, but not if DEAN is a character variable.  If DEAN is a character variable, then you could use:

  where DEAN = "1";

So you could change your %LET statement to

  %let DEAN1A = "1";

Or leave your %let statement as is and instead change your WHERE statement to

  where DEAN = "&DEAN1A" ;

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
laura6728
Obsidian | Level 7

Ugh such a rookie mistake!! DEAN is character not numeric, so I needed the ""!  I also didn't have the "" in the where statement.  I've ran it 4 times now and it is working like a champ.  Thank you so much!

laura6728
Obsidian | Level 7

I made a couple changes and now get the following error log:

7959  PROC TABULATE

7960  DATA=GRDDIST.&STERM.vpi_secgcat;

SYMBOLGEN:  Macro variable STERM resolves to FA14

7961      BY DIV;

7962      WHERE DEAN = &DEAN1A.;

SYMBOLGEN:  Macro variable DEAN1A resolves to 1

ERROR: WHERE clause operator requires compatible variables.

7963      VAR CAMPUS;

7964      CLASS grdcat DPT COURSE name_1 SEC3 /    ORDER=UNFORMATTED MISSING;

7965      CLASSLEV grdcat;

7966      CLASSLEV DPT / STYLE=[OUTPUTWIDTH=1in];

7967      CLASSLEV COURSE / STYLE=[OUTPUTWIDTH=.5in];

7968      CLASSLEV name_1 / STYLE=[OUTPUTWIDTH=2in];

7969      CLASSLEV SEC3 / STYLE=[OUTPUTWIDTH=.5in];

7970

7971      TABLE

7972        /* ROW Statement */

7973           DPT={LABEL=""}*COURSE={LABEL=""}*name_1={LABEL=""}*SEC3={LABEL=""},

7974          /* COLUMN Statement */

7975          grdcat={LABEL=""} *(CAMPUS={LABEL=""} * N={LABEL="#" S=[CELLWIDTH=.5in]} CAMPUS={LABEL=""}

7976           * RowPctN={LABEL="%" S=[CELLWIDTH=.5in]}*f=pctfmt.)

7977          all = 'Total'  *(CAMPUS={LABEL=""} * N={LABEL="#" S=[CELLWIDTH=.5in]} CAMPUS={LABEL=""}

7978           * RowPctN={LABEL="%" S=[CELLWIDTH=.5in]}*f=pctfmt.)    ;

7979      ;

7980  RUN;

CODE:

%let DEAN1A = 1; /* Dean of Arts & Sciences Code (1) */

PROC TABULATE

DATA=GRDDIST.&STERM.vpi_secgcat;

    BY DIV;

    WHERE DEAN = &DEAN1A.;

    VAR CAMPUS;

    CLASS grdcat DPT COURSE name_1 SEC3 /    ORDER=UNFORMATTED MISSING;

    CLASSLEV grdcat;

    CLASSLEV DPT / STYLE=[OUTPUTWIDTH=1in];

    CLASSLEV COURSE / STYLE=[OUTPUTWIDTH=.5in];

    CLASSLEV name_1 / STYLE=[OUTPUTWIDTH=2in];

    CLASSLEV SEC3 / STYLE=[OUTPUTWIDTH=.5in];

    TABLE

      /* ROW Statement */

         DPT={LABEL=""}*COURSE={LABEL=""}*name_1={LABEL=""}*SEC3={LABEL=""},

        /* COLUMN Statement */

        grdcat={LABEL=""} *(CAMPUS={LABEL=""} * N={LABEL="#" S=[CELLWIDTH=.5in]} CAMPUS={LABEL=""}

         * RowPctN={LABEL="%" S=[CELLWIDTH=.5in]}*f=pctfmt.)

        all = 'Total'  *(CAMPUS={LABEL=""} * N={LABEL="#" S=[CELLWIDTH=.5in]} CAMPUS={LABEL=""}

         * RowPctN={LABEL="%" S=[CELLWIDTH=.5in]}*f=pctfmt.)    ;

    ;

RUN; QUIT;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 899 views
  • 0 likes
  • 3 in conversation