Hi everyone !
I wrote the following code to interpolate and log-transform data. I would like to know how to create a macro that does this job. Thank you for your help 😅
proc expand data=Projet.feuille1
from=day to=day
out=Projet.feuille1_interpl;
id Date;
convert France__Equity_Indices__Euronext=index_interpl / observed = total
transformout=(log);
run;
Which parts of the code need to be dynamic?
Thank you for your reply @Kurt_Bremser . Ideally, I'd like a macro with two arguments, the dataset and the variable I want to transform, but I don't think it's possible 😆
It is possible. I see you run this proc once for each variable. Then we need two macros:
1) a simple macro with a button for dataset only, e.g.,
%macro logger (dsn); *dsn - data set name;
Proc expand data=&dsn;
… /* your code here */
Convert &var = &var._interpl;
…
Run;
%mend;
And 2) the driver macro that would iterate over variable list calling the logger macro on each one of them:
E.g.,
%macro driver(list);
https://blogs.sas.com/content/sastraining/2015/01/30/sas-authors-tip-getting-the-macro-language-to-p...
Here is how driver macro calls logger macro:
%macro driver(list); *list - your variable list;
… stuff from blog with countw etc
%let a = %scan… stuff from blog
%logger(&dsn) /*your real dataset name here in parenthesis, not &dsn*/
…
%mend driver;
%let list = var1 var2 var3;
%driver(list) /*this will do the job*/
So if you turn on the
Options mprint; you will see that driver calls logger for each variable.
@pink_poodle thank you very much for taking the time to reply ! I will try your solution 😀
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.