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