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.
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;
Show us the code you have tried.
data vote;
set work.vote;
where candidate_id= (0301 and 0401);
proc print data=vote;
title 'Trump Clinton Votes'
run;
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;
That worked! Thank you very much.
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.
Thank you again! That was very helpful! Would it be possible for me to message you another question I have?
Go for it. I genuinely like helping people on here and trust me there's other things I could be doing on Saturday lol.
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
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).
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.