logo
down
shadow

rewrite these code using macro variable


rewrite these code using macro variable

By : jesus
Date : November 22 2020, 10:54 AM
I hope this helps you . You should read the documentation on how symput() works in relation to the macro compiler and the data step compiler. http://support.sas.com/documentation/cdl/en/mcrolref/68140/HTML/default/viewer.htm#p09y28i2d1kn8qn1p1icxchz37p3.htm
Short story is that your code doesn't work because the macro compiler resolves &&&Qtr and then passes that to the Data Step.
code :
foreach(record in a1):
   call symput(...);
   record.calculated = record.base * <value of &qtr>;


Share : facebook icon twitter icon
which code is more efficient? calling twice a macro or just assigning macro to a variable and use it twice?

which code is more efficient? calling twice a macro or just assigning macro to a variable and use it twice?


By : Sam Welter
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Presumably A_ABS is also a function like macro! The basic trick is to work it out in your head into pseudo machine code - lets say that A_ABS has a similar complexity and doesn't call any more things - then I would put each of them at about 20 op codes making a total of 40 - using them and assigning to a value then using that value twice would be 42 - while "calling" twice would be 80 so you work it out.
BTW - you should only even think about doing this sort of macro, (i.e. function like), if you have tried using a function and your profiler has said it is one of the main reasons that your code is either too big or too slow. The reasons:
How to create Macro variable for each unique region and assigned minimum amount to respective macro variable

How to create Macro variable for each unique region and assigned minimum amount to respective macro variable


By : Belkacem Berchiche
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Select the ids into a macro variable so that you can then loop through them and find the minimum value of amount for each:
code :
data temp;
   input Id $ Region $ Amount $;
   datalines;
     1 A 20 
     1 A 40 
     1 A 50
     2 B 40 
     2 B 30 
     2 B 60 
     3 C 10
     3 C 30
     4 D 20 
     4 D 50 
     4 D 10
    ;
run;

proc sql noprint;
    select distinct region into: region_list separated by " " from temp;
quit;

%macro assign_vars;

    %do i = 1 %to %sysfunc(countw(&region_list.));
    %let this_region = %scan(&region_list., &i.);

        %global min_of_region_&this_region.;

        proc sql noprint;
            select min(amount) into: min_of_region_&this_region. from temp (where = (region = "&this_region."));
        quit;

    %end;


%mend assign_vars;

%assign_vars;

%put &min_of_region_A.;
%put &min_of_region_B.;
%put &min_of_region_C.;
%put &min_of_region_D.;
SAS code incorrectly passing value of macro variable as new column/variable in output

SAS code incorrectly passing value of macro variable as new column/variable in output


By : Ztysjdjdksksmdm
Date : March 29 2020, 07:55 AM
may help you . The macro variable's value just replaces the reference and SAS then interprets the resulting text as the code to run. So you are just describing the difference between these two statements.
code :
invoice = Feb_2018;
invoice = "Feb_2018";
rewrite define macro as c++ code?

rewrite define macro as c++ code?


By : Landschaft
Date : March 29 2020, 07:55 AM
around this issue How i can write this macro as c++ code? , You can write it as an inline function:
Making a macro pass an iterating argument into code bodies provided through a macro variable?

Making a macro pass an iterating argument into code bodies provided through a macro variable?


By : brandon
Date : March 29 2020, 07:55 AM
it fixes the issue In your question, you presented an example that performed console I/O, and I made the comment that console I/O has an overhead substantially larger than that of a loop construct (conditional branch), so it makes very little sense for this type of thing to be unrolled. This is a case where a smart optimizer would probably not unroll, because the increase in code size would not pay dividends in speed. However, based on your follow-up comments, it appears that this was just a little throw-away example, and that I shouldn't have focused so much on the specifics.
In fact, I completely understand what you are saying about MSVC not unrolling loops. Even with optimizations enabled, it tends not to do loop-unrolling unless you are using profile-guided optimizations. Something as trivial as:
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org