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

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

  • , counter);         /*where is this "counter" variable coming from?there was no mention earlier. and what does call missing(of visit
  • ,counter mean
  • /* 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;

    1 ACCEPTED SOLUTION

    Accepted Solutions
    PGStats
    Opal | Level 21

    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

  • , counter) assigns missing values to all the elements of array visit (the star notation means all elements) and to variable counter. It just so happens that this is the first time variable counter is mentioned.
  • hth

    PG

    PG

    View solution in original post

    4 REPLIES 4
    PGStats
    Opal | Level 21

    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

  • , counter) assigns missing values to all the elements of array visit (the star notation means all elements) and to variable counter. It just so happens that this is the first time variable counter is mentioned.
  • hth

    PG

    PG
    robertrao
    Quartz | Level 8

    Thanks PG...

    Good luck on your renewal of SAS

    robertrao
    Quartz | Level 8

    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

    PGStats
    Opal | Level 21

    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

    PG

    sas-innovate-2024.png

    Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

    Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

     

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