Hello
I'm new to this forum and I hope somebody could help me with this problem. I want to check data within an (Person-)ID, check every single line from the first entry to the last and when all checks are done pass to the next Person-ID. I could try it with if first.id or if last.id but then only the first and the last entry are considered what doesn't solve my problem. A simple example is:
id | record code | start date | end date | reason of diminution | record year |
1 | 31 | 2009 | 2009 | ||
1 | 31 | 2009 | 2010 | ||
1 | 21 | 2009 | 2011 | 1 | 2011 |
1 | 21 | 2009 | 2011 | 1 | 2012 |
1 | 21 | 2009 | 2011 | 1 | 2013 |
1 | 21 | 2009 | 2011 | 1 | 2014 |
1 | 21 | 2009 | 2011 | 1 | 2015 |
2 | |||||
2 | |||||
etc. |
The result should be (simplified):
if 'end date' is missing then output: first line is accepted
if 'end date' is missing then output: second line is accepted
if 'end date' not missing and 'end date' eq record year than output: third line accepted
and here full stop, the rest of the lines are not accepted anymore, stop the loop within the group and pass to the next person-id.
So, basic problem: how tell SAS to execute a job within a certain id/group and as soon as the job is finished pass to the next one.
I would appreciate your help, thank you.
Maybe I'm not getting the objective right. It sounds like you're making an easy problem difficult. Wouldn't this give you the result you are asking for?
data want;
set have;
if end_date=. or end_date = record_year;
run;
SAS is still processing every record. But the processing deletes the records that you don't want.
Or are you trying for a different result?
Hello
Thank you for your quick response.
You are perfectly right, I didn't see the woods for the trees!
Indeed, I managed today to solve my problem by following your suggestion, I took only those records I need, the others were not taken into consideration so that I have now a solution.
Nevertheless, in a next step I will sitll have to resolve my problem I tried to explain yesterday akwardly. I will have to compare lines withing the same ID, for example if in line 1 the code of diminution is 8 (I will have 10 different codes) then ignore other lines according to certain conditions within the same ID, etc., sort of do conditions within the same ID until the last ID and when coditions finished the quit for the next ID. I am aware that my example is not the best, I will think about it this week-end but at least I managed to solve the first problem.
Thank you very much
Alecs
There are many scenarios you didn't clarify .
CODE NOT TESTED.
data want;
n=0;
do until(last.id);
set have;
by id;
n+1;
if n=1 and end_date=. then first=1;
if n=2 and end_date=. then second=1;
if n=3 and end_date=record_year then third=1;
end;
n=0;
do until(last.id);
set have;
by id;
n+1;
if n le 3 and first and second and third then output;
end;
run;
end;
Hello Xia Keshan
Thanks for your answer and suggestion.
Indeed as I explained it to the preceding super user I found the solution with his suggestion but in fact I was looking for a solution a you posted. So what I'm looking for is going into this direction you propose and I will try it this week-end.
Thank you very much
Alex
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.