BookmarkSubscribeRSS Feed
Reeza
Super User

The macro doesn't display anything, it inserts value into your table. Check your table.

Num19
Calcite | Level 5

Sorry I meant when I check my table I have a lot of -2, 0 -1, 1 but I don't have decimal numbers.

ballardw
Super User

@Num19 wrote:

Sorry I meant when I check my table I have a lot of -2, 0 -1, 1 but I don't have decimal numbers.


Since you only insert a couple of variables into your table you won't have much info for diagnostics.

 

Likely to generate a lot of junk but try running

 

Options mprint symbolgen;

before the macro. I could show where your values aren't being kept or such.

 

Also what does the %module_2 macro actually look like? That might be the cause since it is setting the value of one of your variables. If it sets a large value for norm then you may not have many times when norm< seuil at the test for insertion.

Num19
Calcite | Level 5

Here is module's code :

%macro module_2(x_1,y_2);
%global norme_2;
%let xcarre=(&x_1**2);
%let ycarre=(&y_2**2);
%let normecarre=%sysevalf(&xcarre+&ycarre);
%let norme_2=%sysfunc(sqrt(&normecarre));
%mend module_2;

%module_2(2,3);
novinosrin
Tourmaline | Level 20

missing %sysevalf here mate!

%let xcarre=(&x_1**2);
%let ycarre=(&y_2**2);
ballardw
Super User

@Num19 wrote:

Here is module's code :

%macro module_2(x_1,y_2);
%global norme_2;
%let xcarre=(&x_1**2);
%let ycarre=(&y_2**2);
%let normecarre=%sysevalf(&xcarre+&ycarre);
%let norme_2=%sysfunc(sqrt(&normecarre));
%mend module_2;

%module_2(2,3);

And use in the other code as this macro is written would be more like:

%module_2(&u., &v.);

%let norm=&norme_2.;

 

Since the macro module_2 does not return a single value but defines a global macro variable to hold the result.

If you want to use %module_2 as function returning value rewrite it as:

%macro module_2(x_1,y_2);
%global norme_2;
%let xcarre=%sysevalf(&x_1**2);
%let ycarre=%sysevalf(&y_2**2);
%let normecarre=%sysevalf(&xcarre+&ycarre);
%sysfunc(sqrt(&normecarre))
%mend module_2;

%put result of %module_2(2,3);

The %put is just to demonstrate it behaves more like a function. After debugging you could reduce that to

 

%macro module_2(x_1,y_2);

%sysfunc(sqrt(%sysevalf(%sysevalf(&x_1**2)+%sysevalf(&y_2**2))))

%mend module_2;
Reeza
Super User

I would highly, highly recommend changing the 'module_2' portion to a function using PROC FCMP and to change this to a data step process. It'll much easier to manage, expand and likely faster. 

Tom
Super User Tom
Super User

Why would you even attempt to do something like this using the macro processor?

Why not just write a data step to implement this logic?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 22 replies
  • 2347 views
  • 3 likes
  • 6 in conversation