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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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