BookmarkSubscribeRSS Feed
u19696098
Fluorite | Level 6
Hi I am having issue in solving below problem from coursera as i am entering the exact code that of solution by but its not returning any records please help;   Level 2 Practice: Subsetting by Multiple Conditions and Creating a Sorted SAS Table
 

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.

  1. 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.

  2. Include only the rows where Category is Mammal and Common_Names includes Fox.

  3. Exclude the Category, Record_Status, Occurrence, and Nativeness columns from the output data.

  4. Submit the program.

  5. Notice that Fox Squirrels are included in the output table. Add a condition in the WHERE statement to exclude rows that include Squirrel.

  6. Submit the program and verify the results.

  7. 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;

19 REPLIES 19
Reeza
Super User

Show the log please.

ChrisNZ
Tourmaline | Level 20

Notice that Fox Squirrels are included in the output table

Common_Names not like '%Squirrel%'

These two don't seem to be compatible.

AMSAS
SAS Super FREQ

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;
Cynthia_sas
SAS Super FREQ

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:

Cynthia_sas_0-1635514518081.png

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.

Cynthia_sas_1-1635514584947.png

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

u19696098
Fluorite | Level 6

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;

 

 

 

69
70 libname out "/home/u19696098/EPG1V2/data" ;
NOTE: Libref OUT refers to the same physical library as PG1.
NOTE: Libref OUT was successfully assigned as follows:
Engine: V9
Physical Name: /home/u19696098/EPG1V2/data
71
72
73
74 data out.fox;
75 set pg1.np_species;
76 where Category="Mammal" and Common_Names like '%Fox%'
77 and Common_Names not like '%Squirrel%';
ERROR: Variable Category is not on file PG1.NP_SPECIES.
78 drop Category Record_Status Occurrence Nativeness;
79 run;
 
WARNING: The variable Category in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable Record_Status in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable Occurrence in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable Nativeness in the DROP, KEEP, or RENAME list has never been referenced.
u19696098
Fluorite | Level 6

Hi All,

I tried in different way and still it shows the error below, please let me know what mistake did i do here.

 

u19696098_0-1635519495670.png

u19696098_1-1635519716285.png

please help me.....

ballardw
Super User

@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.

 

u19696098_0-1635519495670.png

u19696098_1-1635519716285.png

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.

u19696098
Fluorite | Level 6

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

u19696098_0-1635521993189.png

 

u19696098
Fluorite | Level 6

Hi Everyone;

 

Not sure what is happening; if I run with the one of the varibale it gives the result;

u19696098_0-1635523163395.pngu19696098_1-1635523184192.png

 

but when i run the same code for another variable Common Names; it does not work, please please help me....

u19696098_2-1635523290621.pngu19696098_3-1635523307692.png

 

Reeza
Super User
Your code in the images doesn't match what's been posted.

COMMON NAMES and COMMON_NAMES -> you're missing the underscore in your second reference to the variable.
You need to fix your errors in the order they appear, so start from the first error-you're showing the last error when I can see other errors above it.
u19696098
Fluorite | Level 6
Please see above I have correctly entered Common_Names but look at the log, every time i get that even though that variable is under NP library and in species table
Reeza
Super User
Show your full log please to ensure your previous step was also run correctly.
IF common_names doesn't work in this step it shouldn't have worked in the previous step either.
u19696098
Fluorite | Level 6
What i mean is Common_Names did not work at all, If I run the code eliminating this variable at least for one variable Category, it works.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

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.

 

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
  • 19 replies
  • 4849 views
  • 1 like
  • 7 in conversation