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

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!

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