06-19-2012 02:28 PM
How do I create if/do/else logic (I guess using macros) where I am trying to do following. I have only one table (mbr2) where there might be state = MA or other states. In case if line has that MA & product 203 then I want to sort by state and product and eff field in that data set, however if line does not have that criteria then just sort by state and eff. All of this at the end would be in one big data set mbr2
if state=MA and product=203 then do
proc sort data=mbr2;by state product eff ;run;
proc sort data=mbr2;by state eff;run;
06-19-2012 03:49 PM
If I understand what you want you do not need a macro but you need to subset the data twice and then combine.
Proc sort data=mbr2 (where=(state='MA' and product=203)) out=mbrMA203; by state product eff; run;
Proc sort data=mbr2 (where=(state ne 'MA' or product ne 203)) out=mbrOther; by state eff; run;
set mbrMA203 mbrOther;
This will not be sorted by state though. I suspect you are envisioning the MA and 203 into a specific order within the combined data and you have not provided enough information as to where that would be.
06-19-2012 04:41 PM
Thanks. I thought of doing a separate data step as well and then combine it. For some reason I was stuck in the if/then/else world.
This will work most likely. Thanks for your feedback.
06-19-2012 07:08 PM
Another approach would have been to make an additional variable with the desired sort characteristics, probably based on STATE and eff and product.
06-19-2012 10:33 PM
Or you can make a flag variable to avoid spliting the dataset .
proc sort data=mbr2;by state flag eff ;run;
Or in one sql statement.
create table want as
order by state,(product=203),eff;