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 (August 2004, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 30 Aug 2004 17:14:29 -0400
Reply-To:   "Fehd, Ronald J. (PHPPO)" <RJF2@CDC.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Fehd, Ronald J. (PHPPO)" <RJF2@CDC.GOV>
Subject:   Re: if,esle-if statment question
Content-Type:   text/plain; charset="us-ascii"

> From: Rick Kim > In SAS, we have > > IF expression THEN statement1 ; > ELSE statement2 ; > > For instance: > if max(a)<20 then p=0; > else p=1; > > My question is what if I need to put more than one statement > after If expression, like: > > if max(a)<20 then p=0 q=5; > else p=1; > > Is there a way to achieve this?

you can stack as many else-if as you want:

if max(a)<20 then p=0; else if max(a)<30 then p=0.5; else p=1;

this eventually leads to wallpaper code;

better to use a format proc format max 0-20 = 0 21-30 = 0.5 31-hi = 1;

Data X; *...; p = put(Max(A),max.);

also consider the alternate case structure; maxA = max(a); select(maxA); when(<20) p=0; when(<30) p=0.5; otherwise p=1;end;

Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov

Efficiency is intelligent laziness. -David Dunham ... or use of formats


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