BookmarkSubscribeRSS Feed
sas_new
Calcite | Level 5

Can you anyone tell me how to get the macro variable(_stat_desc) result to the macro call.

I dont want to get the data steps in the macro call[You can view the result in the dataset after macro call]

The only difference is having additional data step which causes the Error.

Here the two programs given below for your reference.

Program 1 is present with error i need to rectify. [Just like Program 2 result i am expecting]

/*Program 1. (Error)*/

%macro stat_desc11();

    *** Data step;

    data _null_;

/*        put "Error Found";*/

    run;

    %let _stat_desc=%str(STAT DESCRIPTION);

    &_stat_desc;

%mend stat_desc11;

%put %stat_desc11;

/*For your reference:;*/

data test;

      x="%str(%stat_desc11)";

      put x=;

run;

/*Program 2*/

%macro stat_desc11();

    %let _stat_desc=%str(STAT DESCRIPTION);

    &_stat_desc;

%mend stat_desc11;

%put %stat_desc11;

/*For your reference:;*/

data test;

      x="%str(%stat_desc11)";

      put x=;

run;

Alternate way of solution is also is acceptable,

Thanks in advance,

Thanks,

Kuthubudeen

5 REPLIES 5
LinusH
Tourmaline | Level 20

First, you can't use data step/proc logic in in-line macros.

Second, macros are more sensitive to commenting, especially in in-line macros. So if you comment, try use macro commenting. /* ... */ may also work (at least better than *...; ).

It's hard from your example to see what you are trying to accomplish, so it's hard to give you any other solution.

/Linus

Data never sleeps
sas_new
Calcite | Level 5

Thanks for your quick response Linus,

Before that I just confirm that inline macro means "The macro which will return some value to the macro call"

Please correct me if my assumption is wrong.

My expectation is very simple. I am trying to return some macro variable result to the macro call. In that macro definition i used some data steps.

Is there any alternate way to return variable value to the macro call.[Except using macro parameter].

Thanks,

Kuthubudeen

Peter_C
Rhodochrosite | Level 12

Kuthubudeen

the macro language delivers to the normal submitted language compiler anything it does not regard as syntax that it should execute.

So, if you wish a macro "to return a variable value", everything else must be "consumed by the macro language environment".

Nothing other than the "returned value" must be generated by the macro for the normal submitted language compiler (especially no semi-colons which interrupt statement execution - so no data steps nor proc steps).

The macro language executes things like %substr() and %let and almost all syntax starting with %something. The best known exceptions to this rule are %include and %inc.

Some data step activity might be able to be implemented in the macro language by using %sysfunc() and %syscall, but these exclude many data handling activities which mean that you cannot always have your macro "return a variable value".

good luck

peterC

sas_new
Calcite | Level 5

Hi peter,

Thank you very for your brief explanation. Now i understood thoroughly from your explanation.

Thanks,

Kuthubudeen

LinusH
Tourmaline | Level 20

Your example does not have any parameters in the call.

If this is the case in your real world problem you can call the macro before the data step, have the macro create a global macro variable, and use that in your data step.

Not as neet as you may wished for, but it would work.

Linus

Data never sleeps

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
  • 5 replies
  • 930 views
  • 3 likes
  • 3 in conversation