hi all,
encounter a problem. is it possible to grab an observation and its upper row together?
for example, if i want to draw out harry and peter.
Name Good student
Ben
Peter
Harry Y
Alice
is it always one way to do it like following code?
data want;
set have;
if name in ("peter" , "harry");
run;
can i write a program with designed pattern like
Extract data which name is harry and N-2 observation
and the output should like this:
Name Good student
Ben
Harry Y
thanks in advance
Harry
Hi,
for your setup I would consider something like that:
data have;
infile cards missover;
input Name $ Good_student $ 1.;
cards;
Ben
Peter
Harry Y
Alice
;
run;
data want;
set have curobs=curobs;
if Good_student = "Y" then
do point = max(curobs-1,1) to curobs;
set have point=point;
output;
end;
run;
proc print;
run;
but it doesn't cover situations when you have for example two consecutive "good students", i.e. "Y" in row N and N+1.
All the best
Bart
Do you want to look for Harry or any good student? He may not be the only one 🙂
Hi,
for your setup I would consider something like that:
data have;
infile cards missover;
input Name $ Good_student $ 1.;
cards;
Ben
Peter
Harry Y
Alice
;
run;
data want;
set have curobs=curobs;
if Good_student = "Y" then
do point = max(curobs-1,1) to curobs;
set have point=point;
output;
end;
run;
proc print;
run;
but it doesn't cover situations when you have for example two consecutive "good students", i.e. "Y" in row N and N+1.
All the best
Bart
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: