BookmarkSubscribeRSS Feed
deleted_user
Not applicable
hi

i recently started programming in SAS and i have a couple of questions.

assuming that i have a couple of variables with a number of observations, how do i write a loop so that a procedure is executed on every variable?

for example. i have variables named Y1, Y, .. ,Yn. how do i write a loop so that an if statement is performed for all the variables. so i don't have to type:

if Y1 = x then DELETE;
if Y2 = x then DELETE;
...
if Yn = x then DELETE;


and my second question is if it's possible to print variables from more than one data set using proc print? cus if i have two DATA = the log tells me

WARNING: Ignoring second data set reference
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You can declare an ARRAY statement with a specific set of SAS variable(s) and iterate over the array with a DO / END loop, as shown below:

data _null_;
retain charvar1-charvar5 'x';
ARRAY acharvar (*) $ charvar1 charvar3 charvar5;
do i=1 to dim(acharvar);
if acharvar(i) = 'x' then putlog 'match - ' acharvar(i)= ;
end;
run;

And PROC PRINT cannot be used with more than one data file at a time.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
You can define a view thus:

DATA TEMP / VIEW=TEMP;
SET FILEA FILEB;
RUN;

PROC PRINT DATA=TEMP;
RUN;

Of course, the two files should have compatible variables etc for this to work.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1191 views
  • 0 likes
  • 2 in conversation