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;
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;
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;
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;
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.