Hi all,
I just want to ask a quick question. I have 500 datasets and I want to run the same code for all datasets. The name of my datasets are TV1, TV2, .... TV500. I think I need to use MACRO statements here. So, firstly I write the code for just one dataset:
data KHA. TV1A;
set KHA. TV1;
by datetime;
if first.datetime then V = 0;
V+volume;
if last.datetime then output;
run;
Then I test the following code (I got it from your communities, as well), however I cannot get results:
%MACRO repeat(dslist=);
%DO i=1 %TO %SYSFUNC(COUNTW(&dslist));
%LET ds = %SCAN(&dslist, &i);
DATA &ds;
SET &ds;
by datetime;
if first.datetime then V = 0;
V+volume;
if last.datetime then output;
END;
RUN;
%END;
%MEND repeat;
%repeat(dslist= TV1, TV2, .... TV500);
Could you please help me about that? Could you please give me any other ways to run the same code for multiple assets?
Try passing the list in without comma's separating the data set names.
Also, this is why you shouldn't split your data sets in the first place. Your code doesn't show any mistakes from a quick first glance.
I would suggest running it with a list of two data sets and then posting the output.
Make sure you have the macro debuggging options set:
options mprint symbolgen mlogic;
@Khaladdin wrote:
Hi all,
I just want to ask a quick question. I have 500 datasets and I want to run the same code for all datasets. The name of my datasets are TV1, TV2, .... TV500. I think I need to use MACRO statements here. So, firstly I write the code for just one dataset:
@Reeza hints at a better answer, one that doesn't use macros. Put all the data into a single data set, and then use BY group processing to perform the analysis. Simple, efficient, requires less programming knowledge, it's a win-win-win.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.