## How to delete specific group of observations

Solved
Occasional Contributor
Posts: 10

# How to delete specific group of observations

[ Edited ]

input dataset as below:

data ds;
input idno 1-4 visit \$ 6-11 lab \$17-20 value;
cards;
Su01 visit1 red1 .
Su01 visit1 red2 .
Su01 visit1 red3 .
Su01 visit1 red4 .
Su01 visit1 red1 200
Su01 visit1 red2 10
Su01 visit1 red3 .
Su01 visit1 red4 .
Su01 visit1 red5 .
Su01 visit1 red6 .
Su01 visit1 red7 150
Su02 visit1 red1 300
Su02 visit1 red2 45
Su02 visit1 red3 .
Su02 visit1 red4 30
Su02 visit1 red1 200
Su02 visit1 red2 10
Su02 visit1 red3 .
Su02 visit1 red4 .
Su02 visit1 red5 150
Su02 visit1 red6 250

Su03 visit1 red1 .
Su03 visit1 red2 .
Su03 visit1 red3 .
Su03 visit1 red4 .
;
run;

output should be as below:

idno   visit   lab    value

Su01 visit1 red1 200
Su01 visit1 red2 10
Su01 visit1 red3 .
Su01 visit1 red4 .
Su01 visit1 red5 .
Su01 visit1 red6 .
Su01 visit1 red7 150
Su02 visit1 red1 300
Su02 visit1 red2 45
Su02 visit1 red3 .
Su02 visit1 red4 30
Su02 visit1 red1 200
Su02 visit1 red2 10
Su02 visit1 red3 .
Su02 visit1 red4 .
Su02 visit1 red5 150
Su02 visit1 red6 250

In value variable if the data is . from red1 to redn(lab variable) then I don't want that observations in the output.

if the variable value has . and any value(alphabets,dates,numerics)even at once,then I want the output for lab variable for red1 to redn observations for that specific occurrence (red1 to redn) only. Can you kindly let me know how to get this kind of output for huge data with unknown observations.Thank you in advance.

Accepted Solutions
Solution
‎02-23-2018 03:53 AM
Super User
Posts: 10,609

## Re: How to delete specific group of observations

If I understood what you mean.

``````data ds;
input idno \$ visit \$  lab \$value;
cards;
Su01 visit1 red1 .
Su01 visit1 red2 .
Su01 visit1 red3 .
Su01 visit1 red4 .
Su01 visit1 red1 200
Su01 visit1 red2 10
Su01 visit1 red3 .
Su01 visit1 red4 .
Su01 visit1 red5 .
Su01 visit1 red6 .
Su01 visit1 red7 150
Su02 visit1 red1 300
Su02 visit1 red2 45
Su02 visit1 red3 .
Su02 visit1 red4 30
Su02 visit1 red1 200
Su02 visit1 red2 10
Su02 visit1 red3 .
Su02 visit1 red4 .
Su02 visit1 red5 150
Su02 visit1 red6 250
Su03 visit1 red1 .
Su03 visit1 red2 .
Su03 visit1 red3 .
Su03 visit1 red4 .
;
run;
data have;
set ds;
by idno;
if first.idno or lab='red1' then group+1;
run;
proc sql;
select *
from have
group by group
having n(value) ne 0;
quit;``````

All Replies
Valued Guide
Posts: 554

## Re: How to delete specific group of observations

It seems like you simply don't want the first 4 observations (which is easy to code) but I think you'll have to be specific about why you want them excluded for us to give you meaningful code

Occasional Contributor
Posts: 10

## Re: How to delete specific group of observations

In value variable if the data is . from red1 to redn(lab variable) then I don't want that observations in the output.

if the variable value has . and any value(alphabets,dates,numerics)even at once,then I want the output for lab variable for red1 to redn observations for that specific occurrence (red1 to redn) only. Can you kindly let me know how to get this kind of output for huge data with unknown observations.Thank you.

Super Contributor
Posts: 498

## Re: How to delete specific group of observations

[ Edited ]

Repeating a not very well described problem will most likely not yield better answers.

Occasional Contributor
Posts: 10

## Re: How to delete specific group of observations

Hi,

I couldn't found the merge option to merge the posts.i have updated my reply. thank you.

Super Contributor
Posts: 333

## Re: How to delete specific group of observations

Try using lag(), or retain to keep variabel values across the observations and add logic to keep och remove records depending on previous records.

//Fredrik

Occasional Contributor
Posts: 10

## Re: How to delete specific group of observations

I tried but couldn't get the required output.if possible can you kindly send the sample program code.

Occasional Contributor
Posts: 10

## Re: How to delete specific group of observations

Can anyone kindly help me in getting the required output,if possible with the syntax. Thank you.

Solution
‎02-23-2018 03:53 AM
Super User
Posts: 10,609

## Re: How to delete specific group of observations

If I understood what you mean.

``````data ds;
input idno \$ visit \$  lab \$value;
cards;
Su01 visit1 red1 .
Su01 visit1 red2 .
Su01 visit1 red3 .
Su01 visit1 red4 .
Su01 visit1 red1 200
Su01 visit1 red2 10
Su01 visit1 red3 .
Su01 visit1 red4 .
Su01 visit1 red5 .
Su01 visit1 red6 .
Su01 visit1 red7 150
Su02 visit1 red1 300
Su02 visit1 red2 45
Su02 visit1 red3 .
Su02 visit1 red4 30
Su02 visit1 red1 200
Su02 visit1 red2 10
Su02 visit1 red3 .
Su02 visit1 red4 .
Su02 visit1 red5 150
Su02 visit1 red6 250
Su03 visit1 red1 .
Su03 visit1 red2 .
Su03 visit1 red3 .
Su03 visit1 red4 .
;
run;
data have;
set ds;
by idno;
if first.idno or lab='red1' then group+1;
run;
proc sql;
select *
from have
group by group
having n(value) ne 0;
quit;``````
Occasional Contributor
Posts: 10

## Re: How to delete specific group of observations

A big thank you for your reply with syntax.it helped me so much.

Thank you again.

☑ This topic is solved.