🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 02-18-2016 07:54 PM
(12908 views)
I am trying to sort my data based on the number of appearances in descending order and then only printing the variables host and the fifth day of showing.
I keep getting the following error messages:
ERROR 22-322: Syntax error, expecting one of the following: a name, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
58 run;
ERROR: Variable NAME not found.
ERROR: Variable FIFTH not found.
ERROR: Variable HOST not found.
the code I used is as follows:
proc sort data=snl out=snl2;
by appearances descending;
run;
proc print data=snl2;
var fifth host;
run;
by appearances descending;
run;
proc print data=snl2;
var fifth host;
run;
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
the order come before the variable name;
proc sort data=snl out=snl2;
by descending appearances ;
run;
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You never reference NAME so I have a hard time seeing how that error message belongs to the code you're showing.
Can you post the full code, the full log and the output from PROC CONTENTS.
Date variables sort the same as any other variables. I'm not seeing how a data has any effect on your code at this point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
THis is the entirety of the log with the error messages:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55
56 proc sort data=snl out=snl2;
57 by appearances descending;
_
22
ERROR 22-322: Syntax error, expecting one of the following: a name, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
58 run;
ERROR: Variable NAME not found.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.SNL2 may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.SNL2 was not replaced because this step was stopped.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
59 proc print data=snl2;
60 var fifth host;
ERROR: Variable FIFTH not found.
ERROR: Variable HOST not found.
61 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
62
63 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
75
Here is the code:
data SNL;
length host $ 18;
input Host & $28. Appearances First: mmddyy10. Fifth: date8.;
format first fifth mmddyy8.;
datalines;
Ben Affleck 5 2/19/2000 18-May-13
Alec Baldwin 16 4/21/1990 10-Dec-94
Drew Barrymore 6 11/20/1982 03-Feb-07
Candice Bergen 5 11/8/1975 19-May-90
Chevy Chase 8 2/18/1978 06-Dec-86
Danny DeVito 6 5/15/1982 09-Jan-93
John Goodman 13 12/2/1989 07-May-94
Elliott Gould 6 1/10/1976 16-Feb-80
Tom Hanks 8 12/14/1985 08-Dec-90
Buck Henry 10 1/17/1976 19-Nov-77
Steve Martin 15 10/23/1976 22-Apr-78
Bill Murray 5 3/7/1981 20-Feb-99
Justin Timberlake 5 10/11/2003 09-Mar-13
Christopher Walken 7 1/20/1990 19-May-01
;
run;
proc print data=snl;
format first mmddyy8.;
run;
proc sort data=snl out=snl2;
by appearances descending;
run;
proc print data=snl2;
var fifth host;
run;
length host $ 18;
input Host & $28. Appearances First: mmddyy10. Fifth: date8.;
format first fifth mmddyy8.;
datalines;
Ben Affleck 5 2/19/2000 18-May-13
Alec Baldwin 16 4/21/1990 10-Dec-94
Drew Barrymore 6 11/20/1982 03-Feb-07
Candice Bergen 5 11/8/1975 19-May-90
Chevy Chase 8 2/18/1978 06-Dec-86
Danny DeVito 6 5/15/1982 09-Jan-93
John Goodman 13 12/2/1989 07-May-94
Elliott Gould 6 1/10/1976 16-Feb-80
Tom Hanks 8 12/14/1985 08-Dec-90
Buck Henry 10 1/17/1976 19-Nov-77
Steve Martin 15 10/23/1976 22-Apr-78
Bill Murray 5 3/7/1981 20-Feb-99
Justin Timberlake 5 10/11/2003 09-Mar-13
Christopher Walken 7 1/20/1990 19-May-01
;
run;
proc print data=snl;
format first mmddyy8.;
run;
proc sort data=snl out=snl2;
by appearances descending;
run;
proc print data=snl2;
var fifth host;
run;
I dont understand the error messages at all the dont make sense to me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
the order come before the variable name;
proc sort data=snl out=snl2;
by descending appearances ;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You also need to put descending BEFORE the variable you want to sort descending.
That's what's likely generating your error.