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

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

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

 
--
Paige Miller

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag
PaigeMiller
Diamond | Level 26

 

 

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;

 

 
--
Paige Miller
Sahrseb2020
Calcite | Level 5
Dear Team,
See below the outcome. Code and Log entries shown but no details in the Result Column.

CODE
*****DATA CLASS********;
DATA TEMP;
INPUT RollNumber $ Class $ Age Gender $ 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
;

proc sort data = temp out = want;
by RollNumber;
Where .<10 and Subject = 'Maths' and Sports = 'Football';
run;



LOG 1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 *****DATA CLASS********; 74 DATA TEMP; 75 INPUT RollNumber $ Class $ Age Gender $ Subject $ Sports $; 76 DATALINES; NOTE: The data set WORK.TEMP has 7 observations and 6 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 84 ; 85 86 proc sort data = temp out = want; 87 by RollNumber; 88 Where .<10 and Subject = 'Maths' and Sports = 'Football'; 89 run; NOTE: There were 1 observations read from the data set WORK.TEMP. WHERE (Age>. and Age<10) and (Subject='Maths') and (Sports='Football'); NOTE: The data set WORK.WANT has 1 observations and 6 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 90 91 92 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 104
PaigeMiller
Diamond | Level 26

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.

 
--
Paige Miller
Sahrseb2020
Calcite | Level 5
You are absolutely right. Exactly the code script given work out accurately.

Thanks

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1218 views
  • 0 likes
  • 3 in conversation