- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 09-20-2010 07:23 PM
(1901 views)
all-
is there a way to tell a do loop to reference a vector of numbers for its in index? In other words lets say I have a vector index={3 5 6 7 12 3}. I want the do loop to go through i=3,5,6,7,.... instead of 1,2,3,4,5,.....
cheers
is there a way to tell a do loop to reference a vector of numbers for its in index? In other words lets say I have a vector index={3 5 6 7 12 3}. I want the do loop to go through i=3,5,6,7,.... instead of 1,2,3,4,5,.....
cheers
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data step loop? or macro loop?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's some options:
[pre]
data mydata;
set mydata;
do i=1,3,5,8,6,13;
*-- do stuff with i here --;
put i=;
end;
*-- yet another option --;
do mm='Dec','Jan','Aug','Feb'; *-- no particular order --;
*-- do stuff with mm here --;
put mm=;
end;
run;
%macro myloop;
%let index = 1 3 6 9 2 7;
%do i=1 %to 6; %*best to calculate the dimension of index;
%let idx = %scan( &index, &i, %str( ));
%*-- do stuff with &idx here ---;
%put idx=&idx;
%end;
%mend;
%myloop
[/pre]
[pre]
data mydata;
set mydata;
do i=1,3,5,8,6,13;
*-- do stuff with i here --;
put i=;
end;
*-- yet another option --;
do mm='Dec','Jan','Aug','Feb'; *-- no particular order --;
*-- do stuff with mm here --;
put mm=;
end;
run;
%macro myloop;
%let index = 1 3 6 9 2 7;
%do i=1 %to 6; %*best to calculate the dimension of index;
%let idx = %scan( &index, &i, %str( ));
%*-- do stuff with &idx here ---;
%put idx=&idx;
%end;
%mend;
%myloop
[/pre]
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi:
In a DATA step program, you can provide a list of numbers or character values to be used in a DATA step DO loop, as shown in the program below. If you were using PROC IML or another STAT procedure that allowed DO loops, you would have to consult that documentation for more information.
cynthia
[pre]
data showdo;
do grp='AAA', 'BBB', 'CCC';
do numvar = 1, 3, 5, 7;
do numvar2 = 3, 9;
output;
end;
end;
end;
run;
proc print data=showdo;
run;
[/pre]
In a DATA step program, you can provide a list of numbers or character values to be used in a DATA step DO loop, as shown in the program below. If you were using PROC IML or another STAT procedure that allowed DO loops, you would have to consult that documentation for more information.
cynthia
[pre]
data showdo;
do grp='AAA', 'BBB', 'CCC';
do numvar = 1, 3, 5, 7;
do numvar2 = 3, 9;
output;
end;
end;
end;
run;
proc print data=showdo;
run;
[/pre]