DATA Step, Macro, Functions and more

Macro to create patient profiles

Posts: 29

Macro to create patient profiles

I Have created a macro for creating patient profiles.

%macro patprof ( subjid= );






I have 550 patients in my study and I am calling my macro for every individual patient.

for example :-

%patprof(subjid= 101);



is there any way that which improves my macro code so that I don't need to call my macro all 550 times for each patient.

My subjid are not consecutive numbers.

any help is appreciated.

Posts: 8,169

Re: Macro to create patient profiles

You would have to post your macro in order for anyone to help

Super User
Posts: 6,785

Re: Macro to create patient profiles

Art is right ... without seeing your code we can give just the most general of answers.  With that in mind, there are two approaches that might be possible.

(1) You may be able to change your code so that it processes all patients using a BY SUBJID statement.  If appropriate, subset your data so it contains just the SUBJID values of interest (including the possibility of just a single SUBJID), and feed the subset to your code.

(2) You may be able to keep your code as is, but tell us a data set that contains all relevant values for SUBJID.  Then macro language could generate the 550 calls to your macro, instead of you having to type them.

Good luck.

Regular Contributor
Posts: 195

Re: Macro to create patient profiles


Based on your information provided, if youe SUBJID is not a consecutive numbers, then try the following code..It might works...

%macro test;


           proc sql noprint;

                 select distinct compress(subjid) into :_subjid separated by ' '

                 from have (keep = subjid);


           %let i = 1;

           %let _subjid_ =  %scan(&_subjid.,&i.);

           %do %while(&_subjid_ NE);

                   %patprof(subjid= &_subjid_.);

                   %let i = %eval(&i + 1);

                   %let _subjid_ = %scan(&_subjid.,&i.);


%mend test;


Hope it works...



Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation