```Date: Mon, 9 Mar 2009 14:35:52 -0400 Reply-To: Jake Bee Sender: "SAS(r) Discussion" From: Jake Bee Subject: Re: Program Error Comments: To: Daniel Nordlund In-Reply-To: <6F68293465604AA19258975D20A5F7D7@Aragorn> Content-Type: text/plain; charset=ISO-8859-1 Didn't we solved this? One example: dm 'log' clear; dm 'out' clear; 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 2:30 PM, Daniel Nordlund wrote: > > -----Original Message----- > > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > > Behalf Of SAS Illiterate > > Sent: Monday, March 09, 2009 9:13 AM > > To: SAS-L@LISTSERV.UGA.EDU > > Subject: Re: Program Error > > > > 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 > > What is the error message? Where is the variable numdosage coming from? > Did you try the solution I provided for reading your data? > > Dan > > Daniel Nordlund > Bothell, WA USA > ```

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