BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cyclopsedia
Fluorite | Level 6

Hi all,

I'm a newbie with SAS of just 1 week experience and learning through Coursera and this website. The activity is requesting that in my freq output that I put Species_ID to have results starting with YOSE and Category equal to Mammals.

 

Errors I'm receiving: 

ERROR: Variable Mammal is not on file PG1.NP_SPECIES.

I'm not asking for answers on solving this activity but rather some pointers on what code should be where , Proc FREQ and Proc Print. 

Below is my code; (Please be gentle in criticism lol) 

 

proc freq data=pg1.np_species;
tables Abundance Conservation_Status;
run;

proc print data=pg1.np_species;
var Species_ID Category;
where species_id = "YOSE%" and Category = Mammal;
run;  

Thanks for everyone's time 🙂 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

are you missing to include Mammals within quotes   "   "

proc freq data=pg1.np_species;
tables Abundance Conservation_Status;
run;

proc print data=pg1.np_species;
var Species_ID Category;
where species_id = "YOSE%" and Category = "Mammal";
run;

 

View solution in original post

10 REPLIES 10
novinosrin
Tourmaline | Level 20

are you missing to include Mammals within quotes   "   "

proc freq data=pg1.np_species;
tables Abundance Conservation_Status;
run;

proc print data=pg1.np_species;
var Species_ID Category;
where species_id = "YOSE%" and Category = "Mammal";
run;

 

Cyclopsedia
Fluorite | Level 6

Good question. Checking now..

It looks like when I typed out this issue I WAS missing quotation marks but it doesn't seem to have a difference in my results output.

My goal; is to have species_Id show anything starting with YOSE and Category to point to Mammal only..here are my results with and without quotations. It isn't printing what I've got in PROC PRINT.

 

Does it matter if the Print statement is before or after Proc Freq? 

 

 

 

 

novinosrin
Tourmaline | Level 20

I am going guess here as I do not know what's in  your species data. Perhaps, you are after this?

where upcase(species_id) like "YOSE%" and upcase(Category) = "MAMMAL";

 

/*Task1*/
proc print data=pg1.np_species;
var Species_ID Category;
where upcase(species_id)  like "YOSE%" and upcase(Category) = "MAMMAL";
run;

/*Task 2*/
proc freq data=pg1.np_species;
tables Abundance Conservation_Status;
run;
Cyclopsedia
Fluorite | Level 6

Both responses to this issue are correct, Thanks a TON and it's pretty likely you'll see more posts from me in the future haha but I look forward to getting SAS down . Thanks again for your patience with me 

Cyclopsedia_0-1598033667062.png

 

 

Cyclopsedia
Fluorite | Level 6
I meant to click this as a solution. My apologies.
ballardw
Super User

@Cyclopsedia wrote:

Good question. Checking now..

It looks like when I typed out this issue I WAS missing quotation marks but it doesn't seem to have a difference in my results output.

My goal; is to have species_Id show anything starting with YOSE and Category to point to


If you used "YOSE%" as a LIKE value then you have to use Like "YOSE%" not =.

Or you can use the =: comparison for a "starts with"

where species_id =: "YOSE%" 

 

The order for Proc Freq and Proc Print would really matter if you are creating a data set in Proc Freq that you want to print with Proc Print. But with both (or multiple procedures) using the same input data set then the order in the code is the order the results are created. So if you have a preference of appearance then have the procedures in the desired order.

Cyclopsedia
Fluorite | Level 6

Both responses to this issue are correct, Thanks a TON guys. it's pretty likely you'll see more posts from me in the future haha but I look forward to getting SAS down 🙂 

novinosrin
Tourmaline | Level 20

Welcome to SAS communities @Cyclopsedia 

 

Sir @ballardw , I have noticed you sharing a set of instructions that depicts how to ask a good question. Could you please post that here so that OP can use and follow those well laid instructions in the future

Cynthia_sas
SAS Super FREQ
This practice was meant to have the students use LIKE.
Cynthia
Cynthia_sas
SAS Super FREQ
HI:
The = sign will not work with %. That means you are looking for actual variable values that are exactly YOSE% -- and if you remember from the instructions, there are NOT any values that have a %. You will want to review the video on special WHERE operators. You are supposed to use LIKE for this practice (not =).
Hope this helps,
Cynthia

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 2540 views
  • 3 likes
  • 4 in conversation