SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
chinna0369
Pyrite | Level 9

Hi all, 

 

I have data like below, I am trying to assign sequential order programmatically so that it will automatically rerun when more visits are there in the data.

Can you help me with how can I give sequential order for this?

 

data have;
	input VISIT $1-30 VISITNUM;
	datalines;
Screening 						1 
Cycle 1 Day 1 					8 
Cycle 1 Day 15 					11 
Cycle 2 Day 1 					15 
Cycle 2 Day 15 					16 
Cycle 3 Day 1 					19 
Cycle 3 Day 15 					20 
Cycle 4 Day 1 					22 
Cycle 4 Day 15 					23 
Cycle 5 Day 1 					25 
Cycle 5 Day 15 					28 
Cycle 6 Day 1 					30 
Cycle 6 Day 15 					31 
Cycle 7 Day 1 					33 
Cycle 7 Day 15 					34 
Cycle 8 Day 1 					36 
Cycle 8 Day 15 	 				37 
End of Treatment 				197 
Safety & Efficacy Follow-up 	198 
Unsched 						208 
;
run;

Thanks,

Adithya

4 REPLIES 4
Reeza
Super User
Please show your desired output.
I'm guessing you want something like this but it's unclear.
https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/

chinna0369
Pyrite | Level 9

My desired output is to create AVISITN in sequential order like below.

 

data have;
	input VISIT $1-30 VISITNUM AVISITN;
	datalines;
Screening 						1	1 
Cycle 1 Day 1 					8 	4
Cycle 1 Day 15 					11 	8
Cycle 2 Day 1 					15 	12
Cycle 2 Day 15 					16	16 
Cycle 3 Day 1 					19 	20
Cycle 3 Day 15 					20 	24
Cycle 4 Day 1 					22 	28
Cycle 4 Day 15 					23 	32
Cycle 5 Day 1 					25 	36
Cycle 5 Day 15 					28 	40
Cycle 6 Day 1 					30 	44
Cycle 6 Day 15 					31 	48
Cycle 7 Day 1 					33 	52
Cycle 7 Day 15 					34 	56
Cycle 8 Day 1 					36 	60
Cycle 8 Day 15 	 				37 	64
End of Treatment 				197 68
Safety & Efficacy Follow-up 	198 72
Unsched 						208 76
;
run;

Thanks,

Ad

mkeintz
PROC Star

I guess you are establishing intervals of 4 in AVISITN to allow for inserting new observations that will fall between your current set of observations.  (Also, why is the first interval only 3?).  

 

Assuming your new observations will always get integer values for AVISITN, does this mean you can guarantee there will never be more than 3 new observations between any of the current visits?  

 

Why not make your order variable into a number with integers for the cycle, and two decimals for the day within cycle, such as: 

 

Cycle 1 Day 1                1.01
Cycle 1 Day 15               1.15
Cycle 2 Day 1                2.01
Cycle 2 Day 15               2.15
Cycle 3 Day 1                ..
Cycle 3 Day 15               ..
Cycle 4 Day 1                ..
Cycle 4 Day 15               ..
Cycle 5 Day 1                ..
Cycle 5 Day 15               ..
Cycle 6 Day 1                ..
Cycle 6 Day 15               ..
Cycle 7 Day 1                ..
Cycle 7 Day 15               ..
Cycle 8 Day 1                8.01
Cycle 8 Day 15               8.15
End of Treatment            98.0
Safety & Efficacy Follow-up 99.0

Assuming you never have more than one visit on any given day, you will never have duplication, and you will always have room for new visits.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

This matches your desired output values for Avisitn for the given input data set:

data want;
   set have;
   if _n_=1 then AVISITN=1;
   else AVISITN = (_n_-1)*4;
run;

Please note that when I copy and paste your data step into an editor inconsistent use of TAB characters means that many of the VISITNUM values appear in column 28 leading to a number of incomplete records or invalid data.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1031 views
  • 0 likes
  • 4 in conversation