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

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.

Run your macro as:

%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?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

OK. Two hints.

1. you have to increment %do loops with integers

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

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

OK. Two hints.

1. you have to increment %do loops with integers

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

a_gomesd
Calcite | Level 5

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.

Reeza
Super User

No.

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

Is there a proc plot?

art297
Opal | Level 21

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1287 views
  • 0 likes
  • 3 in conversation