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

I just started a sas module 2 weeks ago and I would like to know why this code is not working properly as the log gives me an error 'Error 180-322: Statement is not valid or it is used out of proper order'

This is the code I am trying to use:

proc sort data=Names out=work.females_names;
var Name Count;
where Gender = 'F';
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I think this is what you want (if not, explain in more detail)

 

proc sort data=Names out=work.females_names(drop=gender);
    by Name Count;
    where Gender = 'F';
run;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

proc sort data=Names out=work.females_names;
var Name Count;
where Gender = 'F';
run;

 

PROC SORT only accepts commands relevant to PROC SORT. There is no VAR command in PROC SORT. Possibly you meant to use

 

by name count;

 

instead of

 

var name count;
--
Paige Miller
hz16g22
Obsidian | Level 7
Thanks for that, is there any way to exclude the gender category as well?
proc sort data=Names out=work.females_names;
by Name Count;
where Gender = 'F';
run;
this code, as you suggested, works but it still includes gender, is there a command that involves excluding variables in PROC SORT?
PaigeMiller
Diamond | Level 26

I think this is what you want (if not, explain in more detail)

 

proc sort data=Names out=work.females_names(drop=gender);
    by Name Count;
    where Gender = 'F';
run;
--
Paige Miller
hz16g22
Obsidian | Level 7
Thanks a lot, I'm still confused as to which proc or data step accepts which command. So this helped a lot!
ballardw
Super User

Please for future questions related to errors, or basically any code that does not produce expected results, you should include the entire proc or data step code along with the errors. Copy the text of the code and all related messages from the log, on the forum open a text box with the </> icon above the message window and paste the entire copied text.

 

Here is an example, using a different data set as we do not have your Names data set, of something very similar to demonstrate:

5    proc sort data=sashelp.class out=work.females_names;
6    var Name Count;
     ---
     180
ERROR 180-322: Statement is not valid or it is used out of proper order.
7    where sex = 'F';
8    run;

The log frequently includes diagnostic characters, such as the underscore characters, to indicate where SAS sees the problem. The Text box is important to preserve the format of the text as the main message windows will reformat text pasted text and may move those indicators to a point that it is hard to tell where the actual issue occurs. In the case above the underscores are under the word VAR. The Error is common wording for misspelled options, may occur because a previous statement was not properly ended or in this case is just plain invalid (trying to use options from one procedure in a different one is a relatively common issue because some statements are common to many different procedures).

 

Note MY code will not run if the Var is replaced with BY, as is the most likely intention of your code, as the SASHELP.CLASS set, which does have Name and Sex does not have a Count variable and would fail at that point, and the reason I have Sex and not Gender in the code.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 777 views
  • 1 like
  • 3 in conversation