Roll Number | Class | Age | Gender | Subject | Sports |
001 | 1 | 10 | M | Maths | Cricket |
002 | 1 | 11 | M | English | Tennis |
003 | 2 | 9 | F | Maths | Football |
004 | 4 | 7 | F | Science | Football |
005 | 3 | 7 | M | Maths | Cricket |
006 | 5 | 10 | F | Science | Tennis |
007 | 3 | 7 | F | Art | Cricket |
Q. Write code to filter student age less than 10 and like football and Maths?
Dear colleagues the table and question underneath is an assignment I am working on. I have taken the step to work on it as seen below but not generating the right answer. Please I need somebody to provide me with the right script code.
Test Solution:
*****DATA CLASS********;
DATA TEMP;
INPUT RollNumber $ Class $ Age Gender $ Subject $ Sports $;
FORMAT SUBJECT SPORTS. ;
DATALINES;
001 1 10 M Maths Cricket
002 1 11 M English Tennis
003 2 9 F Maths Football
004 4 7 F Science Football
005 3 7 M Maths Cricket
006 5 10 F Science Tennis
007 3 7 F Art Cricket
;
RUN;
*PROC CLASS**********;
PROC MEANS;
RUN;
*OUTPUT CLASS********;
*PROC PRINT DATA=TEMP;
WHERE AGE < 10;
By Sports;
;
RUN;
*PROC PRINT DATA=TEMP;
WHERE AGE < 10;
By Subject;
The code provided by @Jagadishkatam and myself produce a SAS data set as the result. If you want something in the Results panel, you can add a PROC PRINT to the code after the desired data set is created.
Please try below code, hope this helps and you are expecting same
proc sort data=temp out=want;
by RollNumber;
where .<Age<10 and Subject='Maths' and Sports='Football';
run;
DATA TEMP;
INPUT RollNumber $ Class $ Age Gender $ Subject $ Sports $;
if age<10 and subject='Maths' and sports='Football';
DATALINES;
001 1 10 M Maths Cricket
002 1 11 M English Tennis
003 2 9 F Maths Football
004 4 7 F Science Football
005 3 7 M Maths Cricket
006 5 10 F Science Tennis
007 3 7 F Art Cricket
;
RUN;
The code provided by @Jagadishkatam and myself produce a SAS data set as the result. If you want something in the Results panel, you can add a PROC PRINT to the code after the desired data set is created.
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.