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 2009, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 9 Mar 2009 12:43:41 -0400
Reply-To:   Jake Bee <johbee@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jake Bee <johbee@GMAIL.COM>
Subject:   Re: Program Error
Comments:   To: SAS Illiterate <sasgeek009@gmail.com>
In-Reply-To:   <16f97904-ee7b-46f2-8d88-6762190cfeb9@s28g2000vbp.googlegroups.com>
Content-Type:   text/plain; charset=ISO-8859-1

Does the following work?

data ndc; length ndc_code $20; infile datalines dlm=','; input age ndc_code $; dosage=input(compress(scan(ndc_code, 2, "-"),'*'),3.); if ((age <= 10) and (dosage > 5)) then dosage_error=1; else dosage_error=0; datalines; 10, 12345-015-12 10, 12345-005-12 10, 12345-001-12 10, 12345-*15-12 10, 12345-*5-12 10, 12345-*45-12 10, 12345-*1-12 20, 12345-*25-12 20, 12345-*5-12 20, 12345-*1-12 20, 12345-*25-12 ; run;

proc print; run;

On Mon, Mar 9, 2009 at 12:12 PM, SAS Illiterate <sasgeek009@gmail.com>wrote:

> On Mar 9, 9:30 am, mlhow...@avalon.net (Mary) wrote: > > Note that there's nothing like an "endif" in SAS- a do..end loop is to = > > group several statements into one block, thus the syntax to the if = > > statement is: > > > > if condition then > > statement; > > > > or > > > > if condition then > > do; > > statement; > > statement; > > statement; > > end; > > > > The following seems to isolate the dosage; I've fixed the if statement = > > and am also assuming only one asterisk; if you have more than one you = > > would need to change this back to your do while like you had. Also I'm = > > using scan rather than find assuming that the - delimits the next thing = > > (I took that off the delimiter on the infile statement).=20 > > > > data ndc; > > informat ndc_code $50. dosage $50.; > > infile datalines dlm=3D","; > > input age ndc_code; > > dosage =3D scan(ndc_code,2,"-"); > > if (substr(dosage,1,1) =3D "*") then > > dosage =3D substr(dosage,2); > > if ((age <=3D 10) and (numdosage > 5)) then > > dosage_error =3D 1; > > datalines; > > 10, 12345-015-12 > > 10, 12345-005-12 > > 10, 12345-001-12 > > 10, 12345-*15-12 > > 10, 12345-*5-12 > > 10, 12345-*45-12 > > 10, 12345-*1-12 > > 20, 12345-*25-12 > > 20, 12345-*5-12 > > 20, 12345-*1-12 > > 20, 12345-*25-12 > > run; > > > > -Mary > > > > > > > > ----- Original Message -----=20 > > From: SAS Illiterate=20 > > To: SA...@LISTSERV.UGA.EDU=20 > > Sent: Monday, March 09, 2009 1:25 AM > > Subject: Program Error > > > > Can someone help me with error in this program > > > > data ndc; > > > > infile datalines dlm=3D",-*"; > > input age ndc_code; > > dosage =3D find(ndc_code, 2, "-"); > > do while dosage =3D "*"; > > dosage =3D substr(dosage, 2); > > end; > > if ((age <=3D 10) and (numdosage > 5)) then > > dosage_error =3D 1; > > end; > > datalines; > > 10, 12345-015-12 > > 10, 12345-005-12 > > 10, 12345-001-12 > > 10, 12345-*15-12 > > 10, 12345-*5-12 > > 10, 12345-*45-12 > > 10, 12345-*1-12 > > 20, 12345-*25-12 > > 20, 12345-*5-12 > > 20, 12345-*1-12 > > 20, 12345-*25-12 > > run;- Hide quoted text - > > > > - Show quoted text - > > Thanks for this, > > But the program still has errors with if statement >


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