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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.