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 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 3 May 2007 10:21:38 -0400
Reply-To:     "data _null_;" <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_;" <datanull@GMAIL.COM>
Subject:      Re: Renaming variables??? but in different way
Comments: To: Rajesh <Rajesh.vishwanath@gmail.com>
In-Reply-To:  <1178193567.570030.168460@u30g2000hsc.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

I have a different understanding from "Jim Groeneveld".

If a column has a missing value "drop" it and all columns with same number suffix. Then re-rank the number suffix to rename the variables.

For me the easiest method is to transpose the data, create two variables from the _NAME_ to contain the Character ROOT and the NUMBER suffix.

Then delete all the observations with NUM identified as missing. Re-rank and transpose back. It takes a lot of steps, and may not scale.

data work.x; input a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 c4; id = _n_; cards; 1 . 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 . 20 21 22 23 2 4 ;;;; run; proc print; run; proc transpose out=work.tall; by id; var a: b: c:; run; data work.tall work.missing(keep=num); set work.tall; attrib root length=$1.; attrib num length=8; root = _name_; num = input(substr(_name_,anydigit(_name_)),f8.); output work.tall; if missing(col1) then output work.missing; run; proc sort data=work.tall; by num; run; proc sort data=work.missing nodupkey; by num; run; data work.tall; merge work.tall(in=in1) work.missing(in=in2); by num; if in2 then delete; run; proc sort data=work.tall; by id root num; run; proc rank data=work.tall out=work.tall; by id root; var num; run; data work.tall; set work.tall; _name_ = cats(root,num); run; proc transpose out=work.new(drop=_name_); by id; id _name_; var col1; run; proc print; run;

On 5/3/07, Rajesh <Rajesh.vishwanath@gmail.com> wrote: > Hi All, > > I have the below dataset for example, > > DATA X; > INPUT A1 A2 A3 A4 B1 B2 B3 B4 C1 C2 C3 C4; > CARDS; > 1 . 3 4 5 6 7 8 9 10 11 12 > 13 14 15 16 17 18 19 20 21 22 23 2 4 > RUN; > > IF THERE IS MISSING THEN I HAVE TO DROP THE VARAIBLES, > > WHERE IN MY CASE A2 IS MISSING,THEN I HAVE TO DROP A2,ALONG WITH THAT > B2 AND C2 SHOULD ALSO BE DROPPED.***************************** > > > (((SUPPOSE C4,B1 WAS MISSING THEN I SHOULD HAVE DROPPED C4,A4 > B4,B1,A1,C1))) > > > ***************************THEN I HAVE LEFT WITH ONLY 12 VARAIBLES AS > > A1 A3 A4 B1 B3 B4 C1 C3 C4 > > I WANT TO RENAME THEM IN SEQUENCE AS BELOW, > > A1 A2 A3 B1 B2 B3 C1 C2 C3 WITH THE VALUES AS IN THE INTIAL > (EX:IN THE ABOVE CASE A1 REMAINS AS IT IS A3 SHOULD BE RENAMED TO A2, > A4 TO A3,B1 REMAINS SAME,B3 TO B2,B4 TO B3 ETC...) > > CAN ANYONE LET ME KNOW HOW TO DO THIS???? > > NOTE: I HAVE AROUND 800 VARIABLES,IT IS VERY DIFFICULT TO DO MANUALLY > EACH AND EVERY TIME WHEN I PERFORM THE JOB,SO I LOOKING FOR A CODE > WHICH WOULD AUTOMATICALLY BY PASSING THE VALUES OR PARAMETERS . > > > THANK YOU, > RAJESH >


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