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 09:43:28 -0400
Reply-To:     Jim Groeneveld <jim2stat@YAHOO.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jim Groeneveld <jim2stat@YAHOO.CO.UK>
Subject:      Re: Renaming variables??? but in different way
Comments: To: Rajesh.vishwanath@GMAIL.COM

Hi Rajesh,

DO NOT SHOUT IN CAPITALS, IT HURTS MY EYES!!!

You now know SAS long enough to know that you can not DROP variables conditionally and that you can not DROP them diffferently between records. A SAS dataset is a rectangular data matrix with all variables for all records. Of course variables may be missing, but they still are there.

So, I presume you "want" something different: if one of the variables A1..A4, B1..B4, C1..C4 has a missing value you want all corresponding variables (starting with the other letters) missing. Furthermore, you want to get rid of gaps by moving non-missing values "downwards" over missing values while actually moving the missing values "up". So you don't "want" to rename variables automatically.

*Tested* code 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 24 RUN;

DATA Y (DROP=R C J); SET X; ARRAY Letter (3,4) A1 - A4 B1 - B4 C1 - C4; * Set corresponding variable to missing if one is missing; DO R = 1 TO 4; IF (MISSING(Letter(1,R)) OR MISSING(Letter(2,R)) OR MISSING(Letter(3,R))) THEN DO C = 1 TO 3; Letter(C,R) = .; END; END; * Shift non-missing values after missing values "down"; DO R = 1 TO 3; *** NOTE: 3, not 4 ! ; IF (MISSING(Letter(1,R))) THEN DO C = 1 TO 3; DO J=R TO 3; Letter(C,J) = Letter(C,J+1); END; Letter(C,4) = .; END; END; RUN;

PROC PRINT DATA=Y; RUN;

Is this what you want?

Regards - Jim. -- Jim Groeneveld, Netherlands Statistician, SAS consultant home.hccnet.nl/jim.groeneveld

On Thu, 3 May 2007 04:59:27 -0700, 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