- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Folks,
I have following kind of data;
Firm var_A
a 1
a 2
a 3
a 4
a 5
b 2
b 1
c 1
i know i can always use "if and then statement" but it will delete only 2,3 and 4.
i want to Delete Firm, if the var_A is between 2 to 4. i don't want to delete the only 2-4 but what i want is to delete the all of the Firm if any on the Var_A comes in the range of 2-4. so after that logic only C will remain. all of Firm A and b should delete.
I will be thankful for any help.
Regards
raq
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There are probably several ways. Here's one:
data want;
delete_flag = 0;
do until (last.firm);
set have;
by firm;
if var_a in (2, 3, 4) then delete_flag=1;
end;
do until (last.firm);
set have;
by firm;
if delete_flag = 0 then output;
end;
drop delete_flag;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There are probably several ways. Here's one:
data want;
delete_flag = 0;
do until (last.firm);
set have;
by firm;
if var_a in (2, 3, 4) then delete_flag=1;
end;
do until (last.firm);
set have;
by firm;
if delete_flag = 0 then output;
end;
drop delete_flag;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You want to delete all obs for a firm if any record of that frim has var_a between 2 and 4.
You can do this with a SET command that reads all var_a between 2 and 4 for a given firm prior to reading all records for the same firm:
data have;
input Firm $1. var_A ;
datalines;
a 1
a 2
a 3
a 4
a 5
b 2
b 1
c 1
run;
data want (drop=exclude);
set have (where=(var_a between 2 and 4) in=found_2_to_4)
have (in=allobs);
by firm;
if first.firm then exclude=ifn(found_2_to_4=1,1,0);
retain exclude;
if allobs=1 and exclude=0;
run;
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------