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 (March 2011, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 30 Mar 2011 09:36:51 -0400
Reply-To:     Peter Flom <peterflomconsulting@MINDSPRING.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter Flom <peterflomconsulting@MINDSPRING.COM>
Subject:      Re: Writing a LOT of IF THEN statements, based on Excel columns
Comments: To: Joe Matise <snoopy369@gmail.com>
In-Reply-To:  <AANLkTimvxMaagxNVv090cLJW35Yk7c3UaYvjZZMtkCQx@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"

Thanks all!

Now I know what to do!

Peter

From: Joe Matise [mailto:snoopy369@gmail.com] Sent: Wednesday, March 30, 2011 9:31 AM To: Peter Flom Cc: SAS-L@listserv.uga.edu Subject: Re: Writing a LOT of IF THEN statements, based on Excel columns

Um, how about writing them as a format? :)

Import the dataset, then modify the columns to be named "Start" (for family_name) and "Label" (for code). Then add a column "Fmtname" and call it whatever you want, say, "FAMILYF". Then add a column 'type' and set it to 'i' (informat - and I forget the difference between 'numeric informat' (i) and 'character informat' (j) so this might need to be j).

Then send it to PROC FORMAT:

proc format lib=yourlib cntlin=yourdataset; quit;

replacing the 'your's with the appropriate values.

Now you can just use: code = input(family,FAMILYF.);

-Joe

On Wed, Mar 30, 2011 at 8:26 AM, Peter Flom <peterflomconsulting@mindspring.com> wrote:

Hello

I figure someone has probably come up with a fast way to do this..

My client has given me data sets with a variable called FAMILY_NAME. In a separate Excel file, she has these FAMILY_NAMES linked to another (numeric) variable. I want to write a bunch of IF THEN ELSE statements along the lines of

IF family_name = XXXX then code = 1;

Else if family_name = XXXX then code = 2;

And so on

The problem is there are 849 different levels. There are also 4 million records. So, I need something more efficient than writing these by hand...

Thanks as always

Peter


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