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

Hi there,

 

I wonder if I can use %do_over or any other loop function to write the following code?

by the way, the values in () are options following "pattern=" in proc sgplot

%drawplot(dot);
%drawplot(solid);
%drawplot(dash);
%drawplot(longdash);

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
rogerjdeangelis
Barite | Level 11
Below is a 'do_over' implementation
and a dosubl implementation.

I am not a fan of 'call execute'.
Hopefully SAS will someday alloe
'%do' and '%if' in open code;

*    _
  __| | ___     _____   _____ _ __
 / _` |/ _ \   / _ \ \ / / _ \ '__|
| (_| | (_) | | (_) \ V /  __/ |
 \__,_|\___/___\___/ \_/ \___|_|
          |_____|
;


%macro drawplot(syms);
  %put ****  &=syms  *******;
%mend drawplot;

%array(sym,values=dot solid dash longdash);
%DO_OVER(sym,macro=drawplot);

****  SYMS=dot  *******
****  SYMS=solid  *******
****  SYMS=dash  *******
****  SYMS=longdash  *******

*    _                 _     _
  __| | ___  ___ _   _| |__ | |
 / _` |/ _ \/ __| | | | '_ \| |
| (_| | (_) \__ \ |_| | |_) | |
 \__,_|\___/|___/\__,_|_.__/|_|

;

data _null_;
  do sym="dot", "solid",  "dash", "longdash";
     call symputx('syms',sym);
     rc=dosubl('
        %drawplot(&syms);
     ');
  end;
run;quit;


****  SYMS=dot  *******
****  SYMS=solid  *******
****  SYMS=dash  *******
****  SYMS=longdash  *******



SOAPBOX ON
I favor this because, the more of us that use it,
the more likely SAS will not deprecate it.
It has enomous potential(like the somewhat deprecated libname engineS), and unlike the
trivial implementation of 'call exceute', it
requires very skilled SAS developers to bring
it to it's full potential.

It is also a language differentiator(ie it
will put WPS and others on their toes.)

SOAPBOX OFF


View solution in original post

2 REPLIES 2
Reeza
Super User

Yes...look at CALL EXECUTE or DOSUBL 

rogerjdeangelis
Barite | Level 11
Below is a 'do_over' implementation
and a dosubl implementation.

I am not a fan of 'call execute'.
Hopefully SAS will someday alloe
'%do' and '%if' in open code;

*    _
  __| | ___     _____   _____ _ __
 / _` |/ _ \   / _ \ \ / / _ \ '__|
| (_| | (_) | | (_) \ V /  __/ |
 \__,_|\___/___\___/ \_/ \___|_|
          |_____|
;


%macro drawplot(syms);
  %put ****  &=syms  *******;
%mend drawplot;

%array(sym,values=dot solid dash longdash);
%DO_OVER(sym,macro=drawplot);

****  SYMS=dot  *******
****  SYMS=solid  *******
****  SYMS=dash  *******
****  SYMS=longdash  *******

*    _                 _     _
  __| | ___  ___ _   _| |__ | |
 / _` |/ _ \/ __| | | | '_ \| |
| (_| | (_) \__ \ |_| | |_) | |
 \__,_|\___/|___/\__,_|_.__/|_|

;

data _null_;
  do sym="dot", "solid",  "dash", "longdash";
     call symputx('syms',sym);
     rc=dosubl('
        %drawplot(&syms);
     ');
  end;
run;quit;


****  SYMS=dot  *******
****  SYMS=solid  *******
****  SYMS=dash  *******
****  SYMS=longdash  *******



SOAPBOX ON
I favor this because, the more of us that use it,
the more likely SAS will not deprecate it.
It has enomous potential(like the somewhat deprecated libname engineS), and unlike the
trivial implementation of 'call exceute', it
requires very skilled SAS developers to bring
it to it's full potential.

It is also a language differentiator(ie it
will put WPS and others on their toes.)

SOAPBOX OFF


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 434 views
  • 2 likes
  • 3 in conversation