Hi,
The following is the code for converting multiple rows of info into single observation using ARRAYS..
Could someone explain to me the highlighted portions....
on page 15-16 of the following paper
http://support.sas.com/resources/papers/97529_Using_Arrays_in_SAS_Programming.pdf
Thanks
proc sort data=expand;
by patient_ID date_of_visit;
run;
data collapse;
set expand;
by patient_ID;
/* Define an array for the new visit variables. */
array visit[4];
/* Retain the variables that are associated with the array. */
retain visit;
/* Clear the visit variables and the counter for each new BY */
/* group (Patient_ID). */
if first.patient_ID then call missing(of visit
/* Increment the counter that is used to reference the element */
/* of array to assign date. */
counter + 1; /*
/* Assign the date to the proper element of the array. */
visit[counter] = date_of_visit; /*what happens when we use the array name followed by counter variable in braces assigned to a new variable?????*/
/* Output one observation per BY group (Patient_ID). */
if last.patient_ID then output;
/* Format and drop variables, as desired. */
format visit: mmddyy10.;
drop date_of_visit counter;
run;
proc print;
run;
Array visit has 4 elements. You access an element of array visit with the bracket notation :
x = visit[2];
visit[3] = y;
the first statement assigns the second element of array visit to x. the second statement assigns y to the third element of array visit.
The statement call missing (of visit
hth
PG
Array visit has 4 elements. You access an element of array visit with the bracket notation :
x = visit[2];
visit[3] = y;
the first statement assigns the second element of array visit to x. the second statement assigns y to the third element of array visit.
The statement call missing (of visit
hth
PG
Thanks PG...
Good luck on your renewal of SAS
Hi ,
I have some more questions regarding the sequence of the code ..
1)If it is the first of the patient then we are telling to put as MISSING.....and then telling it to do Counter+1..........instead the dataset was already set by Patient ID/........So why cant we directly say Counter+1(instead of putting a dot for the first of the patient?????????
Regards
For each patient, you want to start at counter = 1. The statement counter+1 sets the variable counter to 1, whether the previous value of counter was 0 or missing. - PG
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.
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.