BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kaet78ha
Calcite | Level 5

For every parameter, there is needed different scope of subcategories. I'm trying to do these by getting the respective array name for the respective parameter's name in the macro loop, but I can't find the way to get the array name in the loop. 

 

%macro arrs(j);
%do i=1 %to %dim(arr.&j);
category=arr1(i);
output;
%end;
%mend arrs;

data mock;
length param category $200;

array arr1(4) $200 ("Safety Analysis Set [a]" "Safety Run-in Set [b]" "Efficacy Evaluable Set (c)" "Immunogenity Analysis Set (d)");
array arr2(2) $200 ("Completed Study" "Discontinued Study");
array arr3(2) $200 ("Competed Treatment" "Terminated Treatment");
array arr4(6) $200 ("Death" "Lost to Follow-up" "Withdrawal by patient from study" "Termination of study by sponsor"
"Completed 24 months of therapy" "Other");

do id=1 to 6;
param=put(id,param.);
%arrs(id);
output;
end;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What is this %DIM() macro your code is trying to call?

Perhaps you just meant to write:

%macro arrs(j);
do i=1 to dim(arr&j);
  category=arr&j(i);
  output;
end;
%mend arrs;

Or perhaps you wanted to do:

 

%macro arrs;
%local j;
%do j=1 %to 4;
param=put(&j,param.);
do i=1 to dim(arr&j);
  category=arr&j(i);
  output;
end;
%end;
%mend arrs;
data mock;
  length param category $200;
  array arr1(4) $200 ("Safety Analysis Set [a]" "Safety Run-in Set [b]" "Efficacy Evaluable Set (c)" "Immunogenity Analysis Set (d)");
  array arr2(2) $200 ("Completed Study" "Discontinued Study");
  array arr3(2) $200 ("Competed Treatment" "Terminated Treatment");
  array arr4(6) $200 ("Death" "Lost to Follow-up" "Withdrawal by patient from study" "Termination of study by sponsor"
"Completed 24 months of therapy" "Other");
%arrs;
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

What is this %DIM() macro your code is trying to call?

Perhaps you just meant to write:

%macro arrs(j);
do i=1 to dim(arr&j);
  category=arr&j(i);
  output;
end;
%mend arrs;

Or perhaps you wanted to do:

 

%macro arrs;
%local j;
%do j=1 %to 4;
param=put(&j,param.);
do i=1 to dim(arr&j);
  category=arr&j(i);
  output;
end;
%end;
%mend arrs;
data mock;
  length param category $200;
  array arr1(4) $200 ("Safety Analysis Set [a]" "Safety Run-in Set [b]" "Efficacy Evaluable Set (c)" "Immunogenity Analysis Set (d)");
  array arr2(2) $200 ("Completed Study" "Discontinued Study");
  array arr3(2) $200 ("Competed Treatment" "Terminated Treatment");
  array arr4(6) $200 ("Death" "Lost to Follow-up" "Withdrawal by patient from study" "Termination of study by sponsor"
"Completed 24 months of therapy" "Other");
%arrs;
run;
Tom
Super User Tom
Super User

For this problem it is probably easier to forget the arrays and the macro.

data mock;
  length param category $200;
  param=put(1,param.);
  do category=
"Safety Analysis Set [a]","Safety Run-in Set [b]","Efficacy Evaluable Set (c)","Immunogenity Analysis Set (d)";
    output;
  end;
  param=put(2,param.);
  do category="Completed Study","Discontinued Study";
    output;
  end;
...

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 793 views
  • 0 likes
  • 2 in conversation