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.

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
  • 2 replies
  • 620 views
  • 0 likes
  • 2 in conversation