Error "Expecting a Name"

Accepted Solution Solved
Reply
Contributor
Posts: 64
Accepted Solution

Error "Expecting a Name"

I am receiving a very frustrating SAS error when trying to use PROC PANEL."Expecting a name"

I have created some sample code that reproduces the error. Any ideas on what I'm missing?

876        PROC SORT DATA=TEMP OUT=TEMPSORTED;

877         BY OBS_DATE;

878        RUN;

NOTE: There were 26 observations read from the data set WORK.TEMP.

NOTE: The data set WORK.TEMPSORTED has 26 observations and 2 variables.

NOTE: PROCEDURE SORT used (Total process time):

      real time           0.02 seconds

      cpu time            0.01 seconds

879       

880        PROC PANEL DATA=TEMPSORTED;

881         ID OBS_DATE;

                       _

                       22

ERROR 22-322: Expecting a name.

882         LAG DEGREES_F(1) / OUT=TEMP_W_LAG;

ERROR: Variable NAME not found.

883        RUN;

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE PANEL used (Total process time):

      real time           0.06 seconds

      cpu time            0.00 seconds

Here is an entire section of code which reproduces the error:

DATA TEMP;

    INPUT OBS_DATE mmddyy10. DEGREES_F @17;

    FORMAT OBS_DATE mmddyy10.;

    datalines;

11/01/2014  44

11/02/2014  53

11/03/2014  64

11/04/2014  61

11/05/2014  63

11/06/2014  52

11/07/2014  45

11/08/2014  49

11/09/2014  53

11/10/2014  65

11/11/2014  61

11/12/2014  33

11/13/2014  31

11/14/2014  29

11/15/2014  33

11/16/2014  33

11/17/2014  25

11/18/2014  21

11/19/2014  33

11/20/2014  30

11/21/2014  36

11/22/2014  54

11/23/2014  54

11/24/2014  51

11/25/2014  30

11/26/2014  32

;

PROC SORT DATA=TEMP OUT=TEMPSORTED;

  BY OBS_DATE;

RUN;

;

PROC PANEL DATA=TEMPSORTED;

  ID ;

  LAG DEGREES_F(1) / OUT=TEMP_W_LAG;

RUN;


Accepted Solutions
Solution
‎01-09-2015 07:52 PM
Contributor
Posts: 64

Re: Error "Expecting a Name"

I actually figured it out - Proc Panel expects there to be at least 1 category to group by. This is solved by faking it like so:

(I'll post a new thread on ideas on how to do this more eloquently)

DATA TEMP;

  INPUT OBS_DATE mmddyy10. DEGREES_F @17;

  FORMAT OBS_DATE mmddyy10.;

  datalines;

11/01/2014 44

11/02/2014 53

11/03/2014 64

11/04/2014 61

11/05/2014 63

11/06/2014 52

11/07/2014 45

11/08/2014 49

11/09/2014 53

11/10/2014 65

11/11/2014 61

11/12/2014 33

11/13/2014 31

11/14/2014 29

11/15/2014 33

11/16/2014 33

11/17/2014 25

11/18/2014 21

11/19/2014 33

11/20/2014 30

11/21/2014 36

11/22/2014 54

11/23/2014 54

11/24/2014 51

11/25/2014 30

11/26/2014 32

;

/* MAKE A FAKE COPY OF THE DATA AND APPEND TOGETHER INTO 1 DATASET */

DATA TEMP; SET TEMP;

  FAKEGROUP=0;

RUN;

DATA TEMP_FAKE; SET TEMP;

  FAKEGROUP=1;

RUN;

PROC APPEND BASE=TEMP DATA=TEMP_FAKE;

RUN;

/* SORT THE DATA BY THE FAKEGROUP AND OBS DATE */

PROC SORT DATA=TEMP OUT=TEMPSORTED;

  BY FAKEGROUP OBS_DATE;

RUN;

/* USE PROC PANEL TO GENERATE THE LAG VARIABLES */

PROC PANEL DATA=TEMPSORTED;

  ID FAKEGROUP OBS_DATE;

  LAG DEGREES_F(1 2 3 4 5 6 7 8 9 10 11 12) / OUT=TEMP_W_LAG;

RUN;

/* DELETE THE FAKEGROUP SO YOU ARE BACK TO THE ORIGINAL DATASET */

DATA TEMP_W_LAG; SET TEMP_W_LAG(WHERE=(FAKEGROUP=0));

RUN;

View solution in original post


All Replies
Solution
‎01-09-2015 07:52 PM
Contributor
Posts: 64

Re: Error "Expecting a Name"

I actually figured it out - Proc Panel expects there to be at least 1 category to group by. This is solved by faking it like so:

(I'll post a new thread on ideas on how to do this more eloquently)

DATA TEMP;

  INPUT OBS_DATE mmddyy10. DEGREES_F @17;

  FORMAT OBS_DATE mmddyy10.;

  datalines;

11/01/2014 44

11/02/2014 53

11/03/2014 64

11/04/2014 61

11/05/2014 63

11/06/2014 52

11/07/2014 45

11/08/2014 49

11/09/2014 53

11/10/2014 65

11/11/2014 61

11/12/2014 33

11/13/2014 31

11/14/2014 29

11/15/2014 33

11/16/2014 33

11/17/2014 25

11/18/2014 21

11/19/2014 33

11/20/2014 30

11/21/2014 36

11/22/2014 54

11/23/2014 54

11/24/2014 51

11/25/2014 30

11/26/2014 32

;

/* MAKE A FAKE COPY OF THE DATA AND APPEND TOGETHER INTO 1 DATASET */

DATA TEMP; SET TEMP;

  FAKEGROUP=0;

RUN;

DATA TEMP_FAKE; SET TEMP;

  FAKEGROUP=1;

RUN;

PROC APPEND BASE=TEMP DATA=TEMP_FAKE;

RUN;

/* SORT THE DATA BY THE FAKEGROUP AND OBS DATE */

PROC SORT DATA=TEMP OUT=TEMPSORTED;

  BY FAKEGROUP OBS_DATE;

RUN;

/* USE PROC PANEL TO GENERATE THE LAG VARIABLES */

PROC PANEL DATA=TEMPSORTED;

  ID FAKEGROUP OBS_DATE;

  LAG DEGREES_F(1 2 3 4 5 6 7 8 9 10 11 12) / OUT=TEMP_W_LAG;

RUN;

/* DELETE THE FAKEGROUP SO YOU ARE BACK TO THE ORIGINAL DATASET */

DATA TEMP_W_LAG; SET TEMP_W_LAG(WHERE=(FAKEGROUP=0));

RUN;

Respected Advisor
Posts: 4,131

Re: Error "Expecting a Name"

For the approach you've taken you could simplify your code and reduce volumes and passes through the data as done below:

/* SORT THE DATA BY THE FAKEGROUP AND OBS DATE */

PROC SORT DATA=TEMP OUT=TEMPSORTED;

  BY OBS_DATE;

RUN;

/* MAKE A FAKE COPY OF THE DATA AND APPEND TOGETHER INTO 1 DATASET */

DATA TEMPSORTED;

  SET TEMPSORTED end=last;

  FAKEGROUP=0;

  output;

  if last then

    do;

      FAKEGROUP=1;

      output;

      OBS_DATE+1;

      output;

    end;

RUN;

/* USE PROC PANEL TO GENERATE THE LAG VARIABLES */

PROC PANEL DATA=TEMPSORTED;

  ID FAKEGROUP OBS_DATE;

  LAG DEGREES_F(1 2 3 4 5 6 7 8 9 10 11 12) / OUT=TEMP_W_LAG;

RUN;

data TEMP_W_LAG;

  set TEMP_W_LAG(where=(FAKEGROUP=0));

run;

Respected Advisor
Posts: 4,131

Re: Error "Expecting a Name"

For your special case you would also get away with a simple data step like below:

DATA TEMP;

  INPUT OBS_DATE mmddyy10. DEGREES_F @17;

  FORMAT OBS_DATE mmddyy10.;

  datalines;

11/01/2014 44

11/02/2014 53

11/03/2014 64

11/04/2014 61

11/05/2014 63

11/06/2014 52

11/07/2014 45

11/08/2014 49

11/09/2014 53

11/10/2014 65

11/11/2014 61

11/12/2014 33

11/13/2014 31

11/14/2014 29

11/15/2014 33

11/16/2014 33

11/17/2014 25

11/18/2014 21

11/19/2014 33

11/20/2014 30

11/21/2014 36

11/22/2014 54

11/23/2014 54

11/24/2014 51

11/25/2014 30

11/26/2014 32

;

PROC SORT DATA=TEMP OUT=TEMPSORTED;

  BY OBS_DATE;

RUN;

data TEMP_W_LAG(drop=_Smiley Happy;

  set TEMPSORTED;

  array DEGREES_F_ {12} 8. (12*.);

  DEGREES_F_1=lag(DEGREES_F);

  do _i=dim(DEGREES_F_) to 2 by -1;

    DEGREES_F_[_i]=DEGREES_F_[_i-1];

  end;

run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 4448 views
  • 3 likes
  • 2 in conversation