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

HI All,

 

I'm trying to make my program more efficient by using Arrays but can't find a way to make it work. Here is the current program:

 

data final;
  merge visitcal tvisit2 eos;
  by subject;
        
	 if END_OF_TREATMENT ne . then do;
                if CYCLE_1_DAY_14  >= END_OF_TREATMENT then  CYCLE_1_DAY_14= .;
		if CYCLE_2_DAY_1   >= END_OF_TREATMENT then  CYCLE_2_DAY_1 = .;
		if CYCLE_2_DAY_15  >= END_OF_TREATMENT then  CYCLE_2_DAY_15= .;
		if CYCLE_3_DAY_1   >= END_OF_TREATMENT then  CYCLE_3_DAY_1 = .;
		if CYCLE_3_DAY_15  >= END_OF_TREATMENT then  CYCLE_3_DAY_15= .;
		if CYCLE_4_DAY_1   >= END_OF_TREATMENT then  CYCLE_4_DAY_1 = .;
		if CYCLE_4_DAY_15  >= END_OF_TREATMENT then  CYCLE_4_DAY_15= .;
		if CYCLE_5_DAY_1   >= END_OF_TREATMENT then  CYCLE_5_DAY_1 = .;
		if CYCLE_5_DAY_15  >= END_OF_TREATMENT then  CYCLE_5_DAY_15= .;
		if CYCLE_6_DAY_1   >= END_OF_TREATMENT then  CYCLE_6_DAY_1 = .;
		if CYCLE_6_DAY_15  >= END_OF_TREATMENT then  CYCLE_6_DAY_15= .;
		if CYCLE_7_DAY_1   >= END_OF_TREATMENT then  CYCLE_7_DAY_1 = .;
		if CYCLE_7_DAY_15  >= END_OF_TREATMENT then  CYCLE_7_DAY_15= .;
		if CYCLE_8_DAY_1   >= END_OF_TREATMENT then  CYCLE_8_DAY_1 = .;
		if CYCLE_8_DAY_15  >= END_OF_TREATMENT then  CYCLE_8_DAY_15= .;
		if CYCLE_9_DAY_1   >= END_OF_TREATMENT then  CYCLE_9_DAY_1 = .;
		if CYCLE_9_DAY_15  >= END_OF_TREATMENT then  CYCLE_9_DAY_15= .;
		if CYCLE_10_DAY_1  >= END_OF_TREATMENT then  CYCLE_10_DAY_1 = .;
		if CYCLE_10_DAY_15 >= END_OF_TREATMENT then  CYCLE_10_DAY_15= .;
		if CYCLE_11_DAY_1  >= END_OF_TREATMENT then  CYCLE_11_DAY_1 = .;
		if CYCLE_11_DAY_15 >= END_OF_TREATMENT then  CYCLE_11_DAY_15= .;
		if CYCLE_12_DAY_1  >= END_OF_TREATMENT then  CYCLE_12_DAY_1 = .;
		if CYCLE_12_DAY_15 >= END_OF_TREATMENT then  CYCLE_12_DAY_15= .;
            end;
run;

 

Basically I want to make all "Cycles" = . based on the following conditions. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

To save myself some typing, I'm not going to type all of your variable names

 

array x CYCLE_1_DAY_14 CYCLE_2_DAY_1 CYCLE_2_DAY_15;
if end_of_treatment ne . then do i=1 to dim(x);
    if x(i)  >= END_OF_TREATMENT then  x(i) = .;
end;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

To save myself some typing, I'm not going to type all of your variable names

 

array x CYCLE_1_DAY_14 CYCLE_2_DAY_1 CYCLE_2_DAY_15;
if end_of_treatment ne . then do i=1 to dim(x);
    if x(i)  >= END_OF_TREATMENT then  x(i) = .;
end;
--
Paige Miller
HitmonTran
Pyrite | Level 9
thanks for the quick response, but is there a way where i dont have to type all variable names? maybe something like "cycle:" ?
PaigeMiller
Diamond | Level 26

Homework assignment: try it and see if it works.

 

If not, then there are ways of extracting the variables names from DICTIONARY tables into a macro variable that ought to eliminate the need to type all of the variable names.

--
Paige Miller

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