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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.