Hi all,
This newbie would appreciate your advice on how to proceed with this puzzle. I received a data file which has multiple rows (ranging from 2 to 5) per subject concerning technology class-taking. The variables include the course level, year taken, course number, course title, course grade (see below):
I’d like to restructure the data to create a new data set
reflecting the highest course (determined by the course’s last 4-digit number) taken
by each subject (see below).
Many thanks for your help,
elle |
Administrator
|
See SUBSTR and AGGREGATE (MAX) in the FM!
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
Alternatively:
COMPUTE CrsHigh=NUMBER(SUBSTR(LPAD(RTRIM(Course),8),5,4),F4). SORT CASES BY SubjID CrsHigh(D). COMPUTE FILT$=($CASENUM=1 OR SubjID <> LAG(SUBjID)). FILTER BY FILT$. EXE.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by elle lists
Many thanks, Melissa Ives and David Marso for the help. With David referencing the manual and Melissa's decription (below) I developed a clunky but working syntax that : 1) extracts the 4-digits in the course number, 2) aggregates the cases to identify the course number with the highest value, and 3) saves the cases to a new data file.
My awkward concoction is a far cry from David Marso's slick and elegant syntax in his second posting (thank you, David) but a tentative first step for this newbie. Thanks again, Melissa and David.
elle STRING Coursenum(A9). /* This segment Extracts course number's 4-digits COMPUTE Coursenum = SUBSTR(Course,4,4). SORT CASES by SubjectID. /*This segment collapses the cases by highest course number AGGREGATE / outfile=* MODE=ADDVARIABLES /PRESORTED /BREAK = SubjectID /Coursenum_max=MAX(coursenum). DATASET COPY temp. /*This segment copies cases with highest course to new data file DATASET ACTIVATE temp. FILTER OFF. USE ALL. SELECT IF (Coursenum_max = Coursenum). EXECUTE. DATASET ACTIVATE DataSet1. On Fri, Apr 27, 2012 at 10:12 AM, Melissa Ives <[hidden email]> wrote:
|
In reply to this post by David Marso
Thank you, David Marso! The syntax worked like a charm. It's always amazing to see the elegance and fluidity of your writing and certainly sends me to the manual to deconstruct the components. Many thanks, elle On Fri, Apr 27, 2012 at 4:28 PM, David Marso <[hidden email]> wrote: Alternatively: |
Free forum by Nabble | Edit this page |