Dear All;
What the general rule for Macro computation?
I searched on the web and found some example which described the Macro variable trough the
%let
%SYSEVALF
%put
, however still is not clear for me the exact rule.
this is what I want to compute:
Do i = 1 to k;
output{i} = %macro A/%macro B;
End;
the output of both A & B is an integer and I need to save the above command in a loop with k run, means finally my output should be a matrix(array) with k row and 1 column.
Sounds a bit like your trying to use macros as functions - they're not. If you want a function use PROC FCMP.
A do loop as written should be using an array, amd will generate k columns and 1 row, not k rows and 1 column.
Matices aren't really what you should be aiming for, in SAS Base it's variables and rows. If you want matrix functionality use PROC IML
I suspect you don't need a macro but can't say without further information. .
I think it would be beneficial to step back, explain what you're trying to do and post sample input and desired output.
You can probably wrangle your code into working but it but it won't be efficient and even as a learning exercise probably not that useful. You may need a macro but it's hard to tell right now.
SAS macros are mostly used when you want to convert "static" code to "dynamic" code.
My rule of thumb for macros:
1. First make the code work in a static version (=don't use macro coding at all)
2. Only use macro coding if you can't do it with normal Base SAS code
If you can clearly tell us what you have (ideally providing a sample data set created via a SAS data step) and then explain us what you need (ideally also posting a desired output/result), then I'm sure someone here in this forum can help you.
What's really hard to do, is to give you answers based on some most likely not properly working macro code without any data, any log and not even knowing what you actually want to achieve.
Based on just a quick analaysis, here's a recommendation.
First, run %A and %B outside of %C. That will create &A and &B. Then inside %C, refer to &A and &B instead of %A and %B.
If that doesn't solve the problem, then you're probably looking to do something more complex where %A and %B generate results that vary rather than being constant. That would require a different approach.
@Astounding, yes, %A and %B are not constant and within each Do loop their value are changing.
Then if you still need assistance, please explain what you're trying to do and what you have versus what you need.
Thanks @Reeza, somehow, I figure out my question, I replace the macro %A and %B with other methods such that by now, I have a matrix with two columns, then is much easier to divide column 1 by column 2 and save it in the loop.
To answer your initial question as well:
%Let -> creates macro variables. There are other ways as well.
%SYSEVALF -> doing floating point calculations that would require SYSFUNC as well, allows you,to skip one step
%PUT -> displays information in the log
These run the gamut of macro statements/functionality so it's hard to see what you're asking
The documentation is fairly thorough and again can't point to specifics without knowing what you're trying to do in more detail. The appendix contains about 13 examples of commonly written macros.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: