BookmarkSubscribeRSS Feed
trekvana
Calcite | Level 5
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
3 REPLIES 3
WaltSmith
Fluorite | Level 6
data step loop? or macro loop?
WaltSmith
Fluorite | Level 6
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]
Cynthia_sas
SAS Super FREQ
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]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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