The np_species table includes one row for each species that is found in each national park. If necessary, start SAS Studio before you begin.
Reminder: If you restarted your SAS session, you must run the libname.sas program to access your course files.
Open a new program window and write a DATA step to read the pg1.np_species table and create a new permanent table named out.fox in the EPG1V2/output (or EPG194/output) folder.
Include only the rows where Category is Mammal and Common_Names includes Fox.
Exclude the Category, Record_Status, Occurrence, and Nativeness columns from the output data.
Submit the program.
Notice that Fox Squirrels are included in the output table. Add a condition in the WHERE statement to exclude rows that include Squirrel.
Submit the program and verify the results.
Sort the fox table by Common_Names.
What is the value of Common_Names in row one?
data out.fox;
set pg1.np_species;
where Category="Mammal" and Common_Names like '%Fox%'
and Common_Names not like '%Squirrel%';
drop Category Record_Status Occurrence Nativeness;
run;
proc sort data=out.fox;
by Common_Names;
run;
Show the log please.
Notice that Fox Squirrels are included in the output table
Common_Names not like '%Squirrel%'
These two don't seem to be compatible.
Post your log file, also try building up your where clause bit by bit and reviewing the output dataset each time.
Your code looks good, at least when I tried it on a sample:
data got ;
infile cards dlm=" " dsd;
input
category :$20.
common_names :$20.
;
cards ;
fish 'Marlin'
fish 'Dorado'
Mammal 'Squirrel'
Mammal 'Flying Fox'
Mammal 'Fox'
Mammal 'Red Squirrel'
Mammal 'Squirrel Fox'
Mammal 'Fox Squirrels'
;
run ;
data want ;
set got ;
where
Category="Mammal" and
Common_Names like '%Fox%' and
Common_Names not like '%Squirrel%';
put category= common_names= ;
run;
Hi:
Coursera has a Discussion Forum area that is monitored by SAS instructors. The advice you've been given is good advice. If you only did a WHERE to search for the string Fox in the Common_Names column, you'd get some plants like Foxglove or Foxtail. So, adding a compound expression to filter to only get the Mammals, gets you closer to what is needed. However, if you look at an expression as used in this code:
You see that there is still one row that we need to eliminate, so the solution to this (graded) practice requires another condition to eliminate the Fox Squirrel from the output.
So running this final compound WHERE should enable you to find the correct answer to the question. Then you need to look at the resulting table so you can answer the question. You just need to type the name of the animal in row one of the output table.
Since this is a graded practice on the Coursera platform, I am not going to post the answer here.
Cynthia
Thank you all for valuable suggestions, But this is not working for me;
libname out "/home/u19696098/EPG1V2/data" ;
data out.fox;
set pg1.np_species;
where Category="Mammal" and Common_Names like '%Fox%'
and Common_Names not like '%Squirrel%';
drop Category Record_Status Occurrence Nativeness;
run;
proc sort data=out.fox;
by Common_Names;
run;
Hi All,
I tried in different way and still it shows the error below, please let me know what mistake did i do here.
please help me.....
@u19696098 wrote:
Hi All,
I tried in different way and still it shows the error below, please let me know what mistake did i do here.
please help me.....
Sounds like time to go back an make sure that you built the NP.Species data set correctly. Then that you did not modify it to remove the Common_names variable. Spelling counts. If you accidentally created a variable named "Comman_names", for example, that might be one of the causes of the errors. Proc Contents will list all the variables in a data set and basic properties.
So try
Proc Contents data=NP.Species; run;
and see what it tells you about your version of the data set.
Hello,
Common_Names is the correct variable name and Proc contents gives below, not sure why its saying everytime the variable Common_Names not found
Hi Everyone;
Not sure what is happening; if I run with the one of the varibale it gives the result;
but when i run the same code for another variable Common Names; it does not work, please please help me....
It's not common_names, it`s 'Common Names'n (name literal because of the blank).
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.