BookmarkSubscribeRSS Feed
Alecs
Calcite | Level 5

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:

idrecord codestart dateend datereason of diminutionrecord year
1312009  2009
1312009  2010
1212009201112011
1212009201112012
1212009201112013
1212009201112014
1212009201112015
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.

4 REPLIES 4
Astounding
PROC Star

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?

Alecs
Calcite | Level 5

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

Ksharp
Super User

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;

Alecs
Calcite | Level 5

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1469 views
  • 0 likes
  • 3 in conversation