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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
Diamond | Level 26

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

View solution in original post

1 REPLY 1
Cynthia_sas
Diamond | Level 26

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 10644 views
  • 0 likes
  • 2 in conversation