BookmarkSubscribeRSS Feed
Khaladdin
Quartz | Level 8

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?

 

 

3 REPLIES 3
Reeza
Super User

Try passing the list in without comma's separating the data set names. 

Reeza
Super User

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;
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 960 views
  • 0 likes
  • 3 in conversation