Can someone please help me understand this coding solutions in Lesson 4 preparing data 1st practice. The practice session requested Write a DATA step to read the pg1.np_species table and create a new table named fox. Note: If you are using SAS Studio, try creating fox as a permanent table in the EPG194/output folder. Include only the rows where Category is Mammal and Common_Names includes Fox in any case. Exclude the Category, Record_Status, Occurrence, and Nativeness columns. My attempt to code the answer was: data out.fox ; set PG1.NP_SPECIES; keep Category= Mammal and Common_Names like ("fox" "Fox" "FOX"; drop Category Record_Status Occurrence Nativeness; run; solution: data fox;
set pg1.np_species;
where Category='Mammal' and upcase(Common_Names) like '%FOX%';
drop Category Record_Status Occurrence Nativeness;
run; I am confused by when where statement require ' ' or " " and when they do not. I am also confused by what the upcase means. Lastly I am confused why requesting the fox in any case, would = '%FOX%', as requesting the fox, in any case, has nothing to do with if there are letters before fox or after? Also I am confused by the next 2 steps. 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. data fox;
set pg1.np_species;
where Category='Mammal' and upcase(Common_Names) like '%FOX%'
and upcase(Common_Names) not like '%SQUIRREL%';
drop Category Record_Status Occurrence Nativeness;
run; My Attempt: data out.fox; set PG1.NP_SPECIES; where Category='Mammal' and upcase(Common_Names) like '%FOX%' and Common_Names not like '%squirrel%'; drop Category Record_Status Occurrence Nativeness; run; Why do you have to state upcase (Common_Names) when typically you could just say varname not like 'squirrel'. Also why is squirrel written in capital letters, when it is not in capital letters in the table? Last Step, Sort the fox table by Common_Names. My attempt: proc sort data=out.fox; format Common_Names by fox; run; proc sort data=fox;
by Common_Names;
run; I dont understand how we all of a sudden have a fox table? when we only made an out.fox table above? thanks for your time!
... View more