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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 646 views
  • 0 likes
  • 3 in conversation