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;
...

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 474 views
  • 0 likes
  • 2 in conversation