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 2005, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 24 May 2005 14:16:14 -0400
Reply-To:     "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject:      Re: character to numeric with array
Comments: To: sas-l@uga.edu

Alex Pavluck wrote: > Can someone let me know if there is an easier way to do this: > > > ******(Convert from character values to numeric)********; > array CHARS(*) $1 WALK92 JOG92 SWIM92 TENNIS92 AEROB92 DANCE92 BIKE92 > WALK97 JOG97 SWIM97 TENNIS97 AEROB97 DANCE97 BIKE97 > WALK99 JOG99 SWIM99 TENNIS99 AEROB99 DANCE99 BIKE99 > WALK01 JOG01 SWIM01 TENNIS01 AEROB01 DANCE01 BIKE01; > array NUMS(*)WALK92N JOG92N SWIM92N TENNIS92N AEROB92N DANCE92N > BIKE92N WALK97N JOG97N SWIM97N TENNIS97N AEROB97N DANCE97N > BIKE97N WALK99N JOG99N SWIM99N TENNIS99N AEROB99N DANCE99N > BIKE99N WALK01N JOG01N SWIM01N TENNIS01N AEROB01N DANCE01N > BIKE01N; > DO f=1 to 28; > NUMS(f) = INPUT(CHARS(f),1.); > DROP f WALK92 JOG92 SWIM92 TENNIS92 AEROB92 DANCE92 BIKE92 > WALK97 JOG97 SWIM97 TENNIS97 AEROB97 DANCE97 BIKE97 > WALK99 JOG99 SWIM99 TENNIS99 AEROB99 DANCE99 BIKE99 > WALK01 JOG01 SWIM01 TENNIS01 AEROB01 DANCE01 BIKE01; > END;

Seeing how the years stop at 01, I think you've got it done. Move on... But what are you to do with this tangled mess?

Also, if the data continues to grow in this structure (A new year, time for new columns! A new activity, time for more columns) you will be plagued until eternity. Categorical data (activity type and year) does not belong in the metadata (all them column names)

You might consider this more complicated, but adaptive data step:

-untested-

data ActivityNumbersCategoricallyStructured;

set RowsWithPainfullyManyColumns;

array C _character_; do _i_ = 1 to dim(C); * only interested in $1; if vlength(C[_i_]) ne 1 then continue; varname = vname (C[_i_]); p = verify (varname,'90'); * only interested in variables whose name might have a year suffix; if p=0 then continue; * crack the data out from the metadata; activity = substr(varname,1,p-1); yearc = substr(varname,p); year = 2000 + input (yearc,best12.); if yearc = '9' then year = year-100; number = input (C[_i_], best12.); OUTPUT; end; keep activitiy year number; run;

proc tabulate data=ActivityNumbersCategoricallyStructured; class activity year; var number; table year*activity,number; run;

-- Richard A. DeVenezia


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