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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 770 views
  • 0 likes
  • 3 in conversation