Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping Problem with Macro in SAS

Status
Not open for further replies.

sap1958

Technical User
Oct 22, 2009
138
0
0
US
I am using a macro to combine 3 different datasets in SAS (MyList1,MyList2,MyList3).
/*Here is the Macro*/
option mprint symbolgen;
%macro MyList;
data MyListFinal;
%let Status = '1';
if Status = &Status then
set
%do i=1 %to 3;
MyList&i
%end;
;
run;
%mend;
%MyList;

The output is creating one observation and the log gives the following message:
NOTE: DATA STEP stopped due to looping.
NOTE: The data set WORK.MYLISTFINAL has 1 observations and 6 variables.

Why am I getting a looping message. In my do statement I am only looping 3 times based on 3 files.
 
Hi,

I am not clear with the requirement however there number of ways in SAS to combine SAS datasets like using set statement merge statement.

Using PROC sql etc.

However if there is some specific requirement to combine all datasets with name starting with MyList then u can make use of dictionary tables; the code would look like given below;

PROC SQL;

select memname into: name_string separated by ' ' from dictionary.tables where memname like 'MYLIST%';

quit;

now u got the list of dataset names u need to combine into macro variable called name_string.

using data step u can do the further processing;

DATA MyList_Final;
set &name_string;
run;


sasbuddy
 
I think that you're mixing up MACRO and BASE. Remember, MACRO gets resolved before runtime. I don't think that your status variable would work.

Do you always want to combine the 3 datasets? If yes why not just have the macro do a simple SET logic.
Code:
%macro MyList(DataS1,DataS2,DataS3);
  data MyListFinal;
       set &DataS1 &DataS2 &DataS3;
  run;
%mend MyList;

%MyList(ListA,ListB,ListC);

The above MACRO will combine all 3 datasets into the MyListFinal dataset. You could modify the above code to also name the combined dataset. Or, you could also code some logic to include/exclude the datasets using some sort of flag. Just keep in mind that the macro 'FLAGS' are set before the execution. So if your flag (STATUS) relies on a runtime only value it will not work correctly.

Why not post some more specifics about what you need to do and we can try and solve your problem.

I hope that this helped you,
KLAZ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top