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

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;
 
1 ACCEPTED SOLUTION

Accepted Solutions
mohamed_zaki
Barite | Level 11

the order come before the variable name;

proc sort data=snl out=snl2;
by descending appearances ;
run;

View solution in original post

4 REPLIES 4
Reeza
Super User

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.

MadQuidd
Obsidian | Level 7
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;
 
 
I dont understand the error messages at all the dont make sense to me.
mohamed_zaki
Barite | Level 11

the order come before the variable name;

proc sort data=snl out=snl2;
by descending appearances ;
run;
Reeza
Super User

You also need to put descending BEFORE the variable you want to sort descending.

 

That's what's likely generating your error.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 11397 views
  • 3 likes
  • 3 in conversation