Solved
New Contributor
Posts: 2

# Macro + plotting + do question.

Hello, I am having trouble to generate code for an assignment.

Here is the Questions:

1. Write macro to print and plot the exponential function of a given “base” starting in the range “start” – to – “end” calculated by increment “incr”.

Add the title indicating what function you are plotting, in what range and ny what increment.

%exp_plot(.5, -10, 10, .5)

%exp_plot(-.5, -10, 10, .5)

%exp_plot(-.5, -10, 10, .5)

Here is the code i have so far:

%macro exp_plot(base,start,end,incr);

data plot1;

%do i=&start %to &end %by &incr;

result=&base**&i;

output;

%end;

run;

proc plot data=plot1;

plot result;

run;

%mend exp_plot;

%exp_plot(.5, -10, 10,.5)

%exp_plot(-.5, -10, 10,.5)

%exp_plot(-.5, -10, 10,.5)

Can someone please point me in the right direction?

Accepted Solutions
Solution
‎12-06-2014 07:15 PM
PROC Star
Posts: 8,164

## Re: Macro + plotting + do question.

OK. Two hints.

1. you have to increment %do loops with integers

2. I think proc plot will require that you plot two variables

All Replies
Solution
‎12-06-2014 07:15 PM
PROC Star
Posts: 8,164

## Re: Macro + plotting + do question.

OK. Two hints.

1. you have to increment %do loops with integers

2. I think proc plot will require that you plot two variables

New Contributor
Posts: 2

## Re: Macro + plotting + do question.

Thank you Arthur, I managed to figure it out thanks to your hints. If I understand correctly, you cannot use non-integer values to increment in a %do loop therefore the problem is in the question as it is the question that requests us to use the value of 0.5 for incremental.

Super User
Posts: 23,713

## Re: Macro + plotting + do question.

No.

Why are you using %do in a data step, use a regular do loop instead.

Is there a proc plot?

PROC Star
Posts: 8,164

## Re: Macro + plotting + do question.

As said you can use a regular do loop in your data step and a regular do loop CAN use a fractional increment.

🔒 This topic is solved and locked.

Discussion stats
• 4 replies
• 279 views
• 0 likes
• 3 in conversation