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

Hi,

 

I want to export into CSV with following conditions;

 

example data;

 

ID           Practice           status              

1             SMP               Eligible            

2             SMP               Intervention 

3             SMP               Eligible 

4             BMP               Eligible

5             BMP               Eligible

6             SMP               Intervention

 

 

I want to export data excluding observations where 'practice=SMP' and 'status=eligible' and include only with 'practice=SMP' and 'status=intervention' plus where 'practice=BMP' and 'status=eligible'.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc export data=have(where=(not (practice="SMP" and status='Eligible'))) 
    dbms=csv outfile="mycsvfilename.csv";
        /* Any other options you may want go here */
run;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
proc export data=have(where=(not (practice="SMP" and status='Eligible'))) 
    dbms=csv outfile="mycsvfilename.csv";
        /* Any other options you may want go here */
run;
--
Paige Miller
sks521
Quartz | Level 8

Perfect, thanks.

ballardw
Super User

@sks521 wrote:

Hi,

 

I want to export into CSV with following conditions;

 

example data;

 

ID           Practice           status              

1             SMP               Eligible            

2             SMP               Intervention 

3             SMP               Eligible 

4             BMP               Eligible

5             BMP               Eligible

6             SMP               Intervention

 

 

I want to export data excluding observations where 'practice=SMP' and 'status=eligible' and include only with 'practice=SMP' and 'status=intervention' plus where 'practice=BMP' and 'status=eligible'.

 

Thanks


Something like this should work. Replace the path with your actual destination folder and file with the name you want.

proc export 
   data=have(where=( (practice='SMP' and status='Intervention')
                   or(practice='BMP' and status='Eligible') )
            )
              
   outfile= "<path>\file.csv"
   dbms=dlm replace;
   delimiter=',';
run;

You can use the data set options such as WHERE to select records based on values, or KEEP and DROP to select variables almost anywhere a data set is used to control contents or results.

 

BTW. You conditions did not match the actual spelling of the values exhibited in your data for status. Being careless about case is one way to get unexpected results.

sks521
Quartz | Level 8

Thanks for all your help.

 

Best

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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
  • 4 replies
  • 1342 views
  • 0 likes
  • 3 in conversation