BookmarkSubscribeRSS Feed
_vichz
Fluorite | Level 6

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;

 

5 REPLIES 5
_vichz
Fluorite | Level 6

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 😆

 

 

pink_poodle
Barite | Level 11

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.

_vichz
Fluorite | Level 6

@pink_poodle thank you very much for taking the time to reply ! I will try your solution 😀

pink_poodle
Barite | Level 11
Thank you! please let me know if you have any questions.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1187 views
  • 3 likes
  • 3 in conversation