Depending on the value of a macro variable I am looking to output multiple datasets. I am looking to loop this through and I am also looking to do this on multiple input datasets.
%macro data_split;
%do i=1 %to %loop;
data work.test_&&mac_var&loop;
set work.input_dataset;
if col = "&&mac_var&loop" then output test_&&mac_var&loop;
run;
%end;
%mend;
This outputs a number of tables depending on how many times it loops through and gives the correct output depending on the value of mac_var.
However I'm looking at looping it through a number of input_datasets but when trying to add the second loop I'm having issues.
Another solution I thought would be to simply merge these datasets I want into one dataset.
Thanks for any help
You are messing up
%nameand macro variables&name&iand your final value&loopSupposing the macro variables
&mac_var1,&mac_var2, ... and&loopare well defined,this should do the job (I think, because your question is not that clear).
But actually, I would rather specify the values of these macro variables as a parameter
(1) the
scanfunction exists both as data step function and as macro function, but countw only exists as data step function, so you need%sysfuncto call it here.(2) All
;betweendataand here are macro code, so this;is the one closing thedatastatement.PS, next time, give much more details in your question. It is not normal we have to guess what
&&mac_var&imight mean.