BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sophia_SAS
Obsidian | Level 7

Dear SAS community-

 

I'm struggling to write a more elegant code for my current brute method below.  I believe the below code can be done with a simple array and do loop, but I cannot seem to figure out the right combination.  Here's a sample of my current code. Any advice? 

 

Thanks!

 

if rv_mon=1 then do mem1=0; mem2=0; mem3=0; mem4=0; mem5=0; end;

else if rv_mon=2 then do mem2=0; mem3=0; mem4=0; mem5=0; end;

else if rv_mon=3 then do mem3=0; mem4=0; mem5=0; end;

else if rv_mon=4 then do mem4=0; mem5=0; end;

else if rv_mon=5 then do mem5=0; end;

1 ACCEPTED SOLUTION
2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Code not tested, but perhaps something like this

 

data want(drop=i);
	set yourdata;
	array memVars{*} mem1-mem5;
	do i=rv_mon to dim(memVars);
		memVars[i]=0;
	end;
run;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 663 views
  • 2 likes
  • 3 in conversation