Hello,
I am trying to keep only CEO's in my dataset (as opposed to CEO's and other executives). How can I use a keep statement to drop anything in the CEOANN column that isn't "CEO"?
Here's the code I tried:
data paper.Compustat_ExecuComp;
set paper.Compustat_ExecuComp;
if CEOANN = "CEO" then keep;
run;
Any suggestions? Thanks!
Hi, KEEP is a compile time statement that impacts the Program Data Vector being built to hold the data before it is written to disk.
What you want to do is OUTPUT when your condition is met.
However, I recommend that you do NOT use the same name in both your input and output datasets because you will lose all your original data and will not be able to go back to it.
For a model of how to output only the rows for Females to one file and the rows for Males to a different file, see this example using SASHELP.CLASS:
data class_males
class_females;
set sashelp.class;
if sex = 'F' then output class_females;
else if sex = 'M' then output class_males;
run;
proc print data=class_females;
title 'Female Students';
run;
proc print data=class_males;
title 'Male Students';
run;
title;
cynthia
Hi, KEEP is a compile time statement that impacts the Program Data Vector being built to hold the data before it is written to disk.
What you want to do is OUTPUT when your condition is met.
However, I recommend that you do NOT use the same name in both your input and output datasets because you will lose all your original data and will not be able to go back to it.
For a model of how to output only the rows for Females to one file and the rows for Males to a different file, see this example using SASHELP.CLASS:
data class_males
class_females;
set sashelp.class;
if sex = 'F' then output class_females;
else if sex = 'M' then output class_males;
run;
proc print data=class_females;
title 'Female Students';
run;
proc print data=class_males;
title 'Male Students';
run;
title;
cynthia
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.