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

Trying again...

 

 

I'm having trouble with a homework assignment. I need to remove rows using a where and set statement but I'm not sure how exactly to do that?  "In a second datastep remove the rows for all candidates except Trump and Clinton. Use a
set statement with a where statement." Any help would be greatly appreciated. 

 

More info:

A text file called president election 2016.csv on the class website contains data on the 2016
presidential election by county within Minnesota. The first 5 records are as follows:
MN,1,AITKIN,0301,5516,9231
MN,1,AITKIN,0401,3134,9231
MN,1,AITKIN,0801,67,9231
MN,1,AITKIN,1101,124,9231
MN,1,AITKIN,1201,263,9231
There are 6 variables: 1) State abbreviation (MN on all records); 2) a county number (1-87);
3) name of county; 4) candidate code (0301=Trump, 0401=Clinton, 0801=Stein, 1101=McMullin,
1201=Johnson); 5) number of votes cast for that candidate in the county; 6) total votes cast in
that county. Note: There are five records for each county, one for each of the top 5 candidates.
Records for other candidates have been removed.

1 ACCEPTED SOLUTION

Accepted Solutions
tarheel13
Rhodochrosite | Level 12

Did you try to run this? It looks like it will make an error in the log. Try this: 

data vote;
set work.vote;
where candidate_id in (0301,0401);
proc print data=vote;
title 'Trump Clinton Votes'
run;

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

Show us the code you have tried.

--
Paige Miller
sassypixie
Fluorite | Level 6
data vote;
set work.vote;
where candidate_id= (0301 and 0401);
proc print data=vote;
title 'Trump Clinton Votes'
run;
tarheel13
Rhodochrosite | Level 12

Did you try to run this? It looks like it will make an error in the log. Try this: 

data vote;
set work.vote;
where candidate_id in (0301,0401);
proc print data=vote;
title 'Trump Clinton Votes'
run;
sassypixie
Fluorite | Level 6

That worked! Thank you very much. 

tarheel13
Rhodochrosite | Level 12

Happy to help. I don't think you can use the = like that. It would have to be where candidate_id = 0301 or candidate_id = 0401. If you want less typing, then use the in operator. 

sassypixie
Fluorite | Level 6

Thank you again! That was very helpful! Would it be possible for me to message you another question I have?

tarheel13
Rhodochrosite | Level 12

Go for it. I genuinely like helping people on here and trust me there's other things I could be doing on Saturday lol. 

sassypixie
Fluorite | Level 6

Hmm it says I've reach my max number of private messages I can send for now, but I've never sent anyone a private message soo I guess I'll try again later? lol thank you again

tarheel13
Rhodochrosite | Level 12

First you will need to read in the csv file. I would use proc import for that. The where statement is used for sub setting. You need to make the where condition where candidate code IN (0301, 0401).

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 9 replies
  • 1802 views
  • 2 likes
  • 3 in conversation