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 (December 1996, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 10 Dec 1996 23:25:35 -0500
Reply-To:     Mike.Crifassi.crifassi@XSITE.COM
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Mike.Crifassi.crifassi@XSITE.COM
Subject:      Re: creating new varible name using value of another variable

------------------------------------------------------------------------- In <Pine.ULT.3.95.961208155449.1520B-100000@atrium.musc.edu>, on 12/08/96 at 04:04 PM, Jean Michelle Cantey <canteyjm@MUSC.EDU> said:

>I have a dataset where each pregnant woman has many clinic visits. The >vists are not equally spaced nor does each woman follow the same schedule >of visits. So, for each woman I have an observation which includes all >of her visits. The variables measured at each visit are labeled as >follows: vistyp01 vistyp02 vistyp03 ... >wksgest01 wksgest02 wksgest03 ... >sbp01 sbp02 sbp03 ...

>I would like to create a new variable for sbp so that the number >indicates the gestational age at the visit. For example, if wksgest01=18 >and sbp01=120 I want to have a new variable nsbp18=120 (where the 18 in >the new variable name indicates that the measurement was made at 18 >weeks).

>I am not sure how to approach this problem. Any suggestions, ideas, etc. >would be greatly appreciated. Please respond directly to me at: >canteyjm@musc.edu

>Thanks in advance, >Jean

I think this bit of code will work. It may not be the best offered, but...

Thanks, Mike.

/* File: vrfrmvr.sas Date: Sun 12-08-96 | 15:35:20

Variables are vistyp01 vistyp02 vistyp03 ... wksgest01 wksgest02 wksgest03 ... sbp01 sbp02 sbp03 ... */

Data datast ; Input WKSGST01 WKSGST02 WKSGST03 SBP01 SBP02 SBP03 ;

Cards ; 18 24 12 120 100 111 ;

Run ;

Data _null_ ; Set datast end=eof ; ; Array SBP{*} SBP01 SBP02 SBP03 ; Array WKSGST{*} WKSGST01 WKSGST02 WKSGST03 ;

Do i = 1 To 3 ; Call Symput( "Idx" || Compress( Put( i, 1. )), Compress(WKSGST{i})) ; End ; Run ;

%Macro Loop ; ; Data ll ; Set datast ;

/* This can be generalized to any n, though we do have a small problem with the leading zeros... */

%Do i = 1 %To 3 ; ;

%If I lt 10 Then %Let j = 0&i. ; %Else %Let j = &i. ;

NSBP&&Idx.&i. = SBP0&j. ; %End ; %MEnd Loop ;

%Loop ;

Proc Print data=ll ;

/* Output from proc print is:

The SAS System 22:05 Sunday, December 8, 1996 1

OBS WKSGST01 WKSGST02 WKSGST03 SBP01 SBP02 SBP03 NSBP18 NSBP24 NSBP12

1 18 24 12 120 100 111 120 100 111

*/

----------------------------------------------------- -- End of forwarded message ----------------------------------------------------- -- ----------------------------------------------------------- Mike Crifassi crifassi@xsite.com -----------------------------------------------------------


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