Quantcast
Viewing all articles
Browse latest Browse all 310

DO LOOP question

Hello all,

I have a question about how best to accomplish something via a do loop (or perhaps there is a better way?). Hopefully I can explain my data a little bit:

I have data for people with various Cardiovascular conditions/events (heart transplant, congestive heart failure.....). Now, each of these conditions has a description (like what I just listed) but they also come with number IDs. For example:

Description ID
Transplant 123
Congestive Heart Failure 126
Cardiomyopathy 127
Diastolic Heart Failure 128
Severe Heart Block 133
Hypertension 136
....
....

My goal is to perform the same SAS procedures (graphs and whatnot) on all of these Cardiovascular events by using a do-loop.

so for example, let's say I want to do:

title (Cardiovascular description associated with specified ID #);
PROC SGPANEL data=data;
panelby year;
histogram (variable);
where ID= #;
run; quit;


Now I know indicating do i=123 %to 136 will work but in the background SAS will still go through every value from 123 to 136 (but if there is no ID=124 SAS will still try to create a graph for this ID, but nothing will obviously output). Is there a more efficient way to accomplish this without having SAS read through EVERY value between 123 and 136 (can I just specify to do specific values such as 123, 126, 127....)?

My main question is that I want the title to contain the Description associated with a given ID. For example, if my ID=123 and the Heart Transplant is ID 123, then in the title of that SGPANEL I want it to contain HEART TRANSPLANT......if ID=126 then the title should contain CONGESTIVE HEART FAILURE.....and so on - I'm not sure if this requires creating some type of macro variable?. I need to tell SAS which description to use based on which iteration of the do-loop it is on (when i=123 then the description associated with ID=123 should be pulled; when i=126 then description associated with ID=126 should be pulled.....).

Hopefully this makes sense. I'm just curious if anyone can get me pointed in the right direction.

Viewing all articles
Browse latest Browse all 310

Trending Articles