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

 

 

 

Hello,

I have a question about the macros.
Indeed in this simple example, I want to create a multitude of graphics.
Problem is that I have to write each time  %er   (     ,   ).

How to write that once  % er?  But that all graphics are produced.

With% let?  %let p= a e r t y;  ?

 

 

Thanks for your help

 

 

 

 

Data toto;
input a z e r t y;
cards;
1 2 3 4 5 77
6 45 4 8 7 99
4 5 6 8 7 22
1 2 5 4 7 88
;
run;


%macro er (x,y);
proc sgplot data=toto;
scatter x=&x. y=&y./ datalabel;
run;
%mend;
%er (a,z);
%er (a,e);
%er (a,r);
%er (a,t);
%er (a,y);
%er (z,a);
%er (z,e);
%er (z,r);
%er (z,t);
%er (z,y);
%er (e,a);
%er (e,z);
%er (e,r);
%er (e,t);
%er (e,y);

 ...

.........It is too long  😕

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well first off, you would be better off modelling your toto dataset in such a way that you don't have to do this, i.e. just two columns x and y.

 

But you can do something like:

Data toto;
input a z e r t y;
cards;
1 2 3 4 5 77
6 45 4 8 7 99
4 5 6 8 7 22
1 2 5 4 7 88
;
run;
%macro er (x,y);
%put x=&x. y=&y.;
%mend;

data _null_;
array tmp {*} a z e r t y;
do i=1 to 6;
do j= i+1 to 6;
call execute(cats('%er (x=',vname(tmp{i}),',y=',vname(tmp{j}),');'));
end;
end;
run;

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well first off, you would be better off modelling your toto dataset in such a way that you don't have to do this, i.e. just two columns x and y.

 

But you can do something like:

Data toto;
input a z e r t y;
cards;
1 2 3 4 5 77
6 45 4 8 7 99
4 5 6 8 7 22
1 2 5 4 7 88
;
run;
%macro er (x,y);
%put x=&x. y=&y.;
%mend;

data _null_;
array tmp {*} a z e r t y;
do i=1 to 6;
do j= i+1 to 6;
call execute(cats('%er (x=',vname(tmp{i}),',y=',vname(tmp{j}),');'));
end;
end;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 323 views
  • 0 likes
  • 2 in conversation