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

What is the value of Common_Names in row one? I encountered this problem and I am not sure I understand what value is required. below is the code. 

libname out "~/EPG1V2/output";
*libname out "~/EPG194/output";

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;

1 ACCEPTED SOLUTION

Accepted Solutions
russt_sas
SAS Employee

Not sure what you mean here.  The percent is a wildcard that says match any character, so your WHERE below is checking to see if the variable COMMON_NAMES contains a string that has Fox or does not contain the string Squirrel.  Using the wildcard means that aFoxb would be accepted.  If this is not what you are looking for, please explain further.

 

where Category='Mammal' and Common_Names like
'%Fox%' and Common_Names not like
'%Squirrel%';

View solution in original post

3 REPLIES 3
russt_sas
SAS Employee

Not sure what you mean here.  The percent is a wildcard that says match any character, so your WHERE below is checking to see if the variable COMMON_NAMES contains a string that has Fox or does not contain the string Squirrel.  Using the wildcard means that aFoxb would be accepted.  If this is not what you are looking for, please explain further.

 

where Category='Mammal' and Common_Names like
'%Fox%' and Common_Names not like
'%Squirrel%';

Nelson12
Calcite | Level 5
I got the point now. Thank You
ballardw
Super User

WE don't have your data set. Even if we did there is a chance that your have sorted the data set. So questions about "row one" are a bit difficult to answer. And row one from the input set or the output data set?

 

The conditions are saying the output values should come from Category='Mammal' (remove category from the Drop statement to see the variable in the output set) with Common_names containing "Fox" and not containing "Squirrel". So you might have values of Common_names like "Red Fox" "Gray Fox"  but should not see "Fox Squirrel" (or "Squirrel Fox")

 

Did you run the code? What did the output look like? (Proc Print data=out.fox;run; if you don't know how to print yet)

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 3 replies
  • 401 views
  • 0 likes
  • 3 in conversation