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
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;
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;
Perfect, thanks.
@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.
Thanks for all your help.
Best
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.