Hi All,
I need help in programming part. I have dataset :
Dataset:
Obs Subject ADY Avisitn Avalc
1 101 86 12 PR
2 101 186 17 PD
3 101 257 24 PR
4 101 327 29 PR
5 101 382 32 PR
6 102 76 14 PR
7 102 128 17 CR
8 102 188 24 CR
9 102 253 29 CR
I need a output these way:
Obs Subject ADY Avisitn Avalc
1 101 86 12 PR
2 101 186 17 PD
3 101 257 24 PR
5 101 382 32 PR
6 102 76 14 PR
7 102 128 17 CR
9 102 253 29 CR
So i dont need 4th and 8 th observation in the output. I am trying to use lag function but its not working properly. Could you please send me the piece of code to get the same output as above. Thanks in Advance.
Try next code:
data want;
set have;
by subject Avalc notsorted ;
if first.avalc or last.avalc then output;
run;
Hi mounikag,
If you need to throw out some observations by their numbers, you can do it this way:
data WANT;
set HAVE;
if _n_ in (4,8) then delete;
run;
Hope this helps.
Hi Leonid,
Thanks for your reply . I can't delete by using the observations because i have like 1000 of observations . Sorry if you misunderstood my question . If data has three immediate consecutive avalc values it should display first and last aval . So i mean if the data has
DAta:
PR
CR
CR
SD
SD
SD
So i should get the output has :
PR
CR
SD
SD
Try next code:
data want;
set have;
by subject Avalc notsorted ;
if first.avalc or last.avalc then output;
run;
@mounikag wrote:
Hi All,
I need help in programming part. I have dataset :
Dataset:
Obs Subject ADY Avisitn Avalc
1 101 86 12 PR
2 101 186 17 PD
3 101 257 24 PR
4 101 327 29 PR
5 101 382 32 PR
6 102 76 14 PR
7 102 128 17 CR
8 102 188 24 CR
9 102 253 29 CR
I need a output these way:
Obs Subject ADY Avisitn Avalc
1 101 86 12 PR
2 101 186 17 PD
3 101 257 24 PR
5 101 382 32 PR
6 102 76 14 PR
7 102 128 17 CR
9 102 253 29 CR
So i dont need 4th and 8 th observation in the output. I am trying to use lag function but its not working properly. Could you please send me the piece of code to get the same output as above. Thanks in Advance.
What is the RULE involved with why the 4th and 8th observation are to be removed? A value? A combination of values? A count of rows within subject? You just don't like 4 and 8? A specific value on the previous row?
It is very easy to create a solution that will remove those two specific records but that quick and easy solution is almost certainly not going to work for a general case in data sets with 1000's of records where you want to remove 100's of records.
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.