LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2003, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 21 May 2003 11:19:52 -0400
Reply-To:     "Cacialli, Doug" <Doug_Cacialli@URMC.ROCHESTER.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Cacialli, Doug" <Doug_Cacialli@URMC.ROCHESTER.EDU>
Subject:      Any suggestions?
Content-Type: text/plain

Morning everyone!

I'm hoping that some of you can provide me with some criticisms and/or suggestions about some code I've written.

The following code is part of a macro. One of the things the macro is designed to do is subset a data set on first or last observation for every value of a given variable. Of course to do this, I need to specify how the data set is sorted. I could specify a parameter to input the sort variable(s), but I'd like to automate this as much as possible. So what I've done is:

PROC CONTENTS DATA = &INPUTDS._SORTED OUT = &INPUTDS._CONTENTS NOPRINT; RUN; PROC TRANSPOSE DATA = &INPUTDS._CONTENTS OUT = TRANSPOSED PREFIX = SORT; WHERE SORTEDBY ^= .; BY MEMNAME; ID SORTEDBY; VAR NAME; RUN; DATA SORTVARS; SET TRANSPOSED; ARRAY NSORTVARS (*) SORT: ; NVARS = DIM(NSORTVARS); IF (NVARS = 1) THEN CONCATENATED = TRIM(LEFT(SORT1)); ELSE IF (NVARS = 2) THEN CONCATENATED = TRIM(LEFT(SORT1)) || ' ' || TRIM(LEFT(SORT2)); ELSE IF (NVARS = 3) THEN CONCATENATED = TRIM(LEFT(SORT1)) || ' ' || TRIM(LEFT(SORT2)) || ' ' || TRIM(LEFT(SORT3)); ELSE IF (NVARS = 4) THEN CONCATENATED = TRIM(LEFT(SORT1)) || ' ' || TRIM(LEFT(SORT2)) || ' ' || TRIM(LEFT(SORT3)) || ' ' || TRIM(LEFT(SORT4)); CALL SYMPUT ('SRTVARS',CONCATENATED); RUN;

There will never be more than four sort variables. The input data set will always be sorted, and of the form '[DATA SET NAME]_SORTED'. &INPUTDS is a parameter of the macro. After &SRTVARS is created by CALL SYMPUT, it is used later in the BY statement of the data set where the subsetting takes place.

Does anyone see any obvious ways that this can be made more efficient or less cumbersome? Thanks for any thoughts.

Doug out.

--------------------------------------------------- Douglas Cacialli - Data Manager / Data Analyst Sleep and Depression Research Laboratory University of Rochester Medical Center 300 Crittenden Blvd. - Box PSYCH Rochester, New York 14642 Phone: (585)273-3309 Fax: (585)506-0287 ---------------------------------------------------


Back to: Top of message | Previous page | Main SAS-L page