Hi Everyone,
I want to run my code for different values of variable lookback using this rule
Do lookback=4 to 10 by 2;
I know that I can make a macro say %macro mymacro(lookback=) and then list the value.
This code is for demonstration purpose only.
I really want to make a DO to pass the value into the body of the code.
Could you please help me with that?
Thank you,
HHC
Do lookback=4 to 10 by 2;
data pfm; set pfm;
drop i j l1 h1;
lowest=1000;
highest=0;
i+1;
do j=i to i+ lookback;
set pfm (keep=low high rename =(low=l1 high=h1)) point=j;
if lowest>l1 then lowest=l1;
if highest<h1 then highest=h1;
end;
run;
data pfm; set pfm;
rename
lowest=lowest_lookback *How can I turn it into number lookback?;
highest=highest_lookback;
run;
....
%macro test;
%do oldvar=2 %to 6 %by 2;
data test&oldvar;
set sashelp.class;
run;
%end;
%mend;
%test;
For discrete value
%let oldvar=4 5 20;
%macro test;
%do i=1 %to %sysfunc(countw(&oldvar));
%let newvar=%scan(&oldvar,&i);
data test&newvar;
set sashelp.class;
run;
%end;
%mend;
%test;
Message was edited by: Harry Ng
I'm not sure quite what you are attempting to actually accomplish. Are you trying to use the loop to call the two steps with data pfm within the loop?
If you post some example data, as data step code preferably, and what the desired output should be that would help.
Also for test purposes I would think very carefully about using the:
Data pfm; set pfm;
structure. Reusing the same data set before you have the results you need leads to difficulty determining where a re-assignment error occurs.
%macro test;
%do oldvar=2 %to 6 %by 2;
data test&oldvar;
set sashelp.class;
run;
%end;
%mend;
%test;
For discrete value
%let oldvar=4 5 20;
%macro test;
%do i=1 %to %sysfunc(countw(&oldvar));
%let newvar=%scan(&oldvar,&i);
data test&newvar;
set sashelp.class;
run;
%end;
%mend;
%test;
Message was edited by: Harry Ng
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.