data total1; set total;
if (a1_grade_04050=1) or (a1_grade_05060=1) or (a1_grade_06070=1) then output ;
run;
data total1; set total;
if (a1_grade_04050=1) and (a1_grade_05060=1) and (a1_grade_06070=1) then output ;
run;
Using OR should work.
If you get unwanted results please post example of your input and relevant output
to display why it is not wanted
Thank you shmuel and ballardw.
Data cannot be changed, neither can be variable names.
With the or statement I get the correct number of observations in the log file, however when I look at the tables, also other grades, such as 0 (which is kindergarten), grade 2, and grade 3 are included. And I want just grade 1.
Your criteria is that any of the values are 1. This means the other values can be values other than 1.
Change your proc freq to be
var1*var2*var3/list
Then you'll see that at least one is a 1 in all cases.
You should describe, or better yet provide examples of, your data. The instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to create data step code that can be posted here to recreate your data set.
It will also help to provide an example of what the desired result for your example data would would be.
From the variables you show and your request "grade 1 in year 0405" part of the issue could well be the data structure. When variable names contain information you need to query or manipulate then that is a sign that the data should be restructured. In general a variable named Grade with values like 1 and another variable Year with values like '0405' or '0506' (if those indicate school year 2004 to 2005 or 2005 to 2006 that's another issue) then the desired result would be nearly trivial:
If grade=1 and year in ('0405' '0506' '0607');
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.