Date: Wed, 17 May 2000 09:57:38 -0400
Reply-To: Dankwart Plattner <dankwart.plattner@KFW.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dankwart Plattner <dankwart.plattner@KFW.DE>
Subject: Re: Problem with If/then command
On Wed, 17 May 2000 08:53:02 -0400, Muhlbaier, Lawrence H.
<lawrence.muhlbaier@DUKE.EDU> wrote:
>Panos,
>
>Your IF/THEN syntax looks correct. I suspect that there is a problem in
>the comparison part of the IF statement. E.G. do you have records in the
>data that really match the criteria that you have specified. For
>instance, the comparison on CRN will fail if you have leading blanks and
>the comparison on last name will fail if you have mixed case in the
>data. Adding some diagnostic code will help, say
>
>if (crn="A77954") THEN PUT crn= surname= ce_admit=;
>
>A couple of other notes, as I've followed this thread a while. The
>INFORMAT only gets applied when data are brought in from external sources
>(as in an INPUT statement); it DOES NOT WORK with most data
>transformations within a data step. Also, 9 and 99 are legitimate SAS
>dates (they are both in early 1960).
>
>Doc
>
>Panos PAPANIKOLAOU wrote:
>
>> Dear All,
>>
>> I have run the SAS log listed below. I have used the If/then coomand
>> to convert the values for variable DATE1ST from dates to either .R
>> (.A) or 99(9) respectively. I have tried the if/then command in both
>> ways. SAS seems that it does not understand the if/then command and
>> it therefore ignores what the command. I would appreciate very much
>> if i could get your assistance on how to solve this problem.
>>
>> In addition, when I use the proc print to get the values of the
>> variables DATE1ST and DATE_SUB, SAS produces a printout with missing
>> values -- a sinle dot for each single value. That's fine up to a
>> point but I am wondering what I need to do to get the values of 99
>> (.R) or similar values (as listed in proc format structure) rather
>> than a single dot. I would value your comments.
>>
>> Thank you very much for taking your time to consider my request.
>> I look forward to hearing from you.
>>
>> Regards
>> Panos
>>
>> /* ****************** The SAS Log ****************** */
>>
>> 6526 libname mylib 'C:\panos\sores\sas_data\sas9798' ;
>> NOTE: Libref MYLIB was successfully assigned as follows:
>> Engine: V612
>> Physical Name: C:\panos\sores\sas_data\sas9798
>> 6527
>> 6528 proc format library=mylib ;
>> 6529 invalue ourdat
>> 6530 '99' = .R /* Not Recorded */
>> 6531 '9' = .A /* Not Available */
>> 6532 '999' = .I /* Invalid ie Non Valid cases */
>> 6533 other = [ ddmmyy10. ] ;
>> WARNING: Informat OURDAT is already on the library.
>> NOTE: Informat OURDAT has been output.
>> 6533 /* Actual dates */
>> 6534 run ;
>>
>> NOTE: The PROCEDURE FORMAT used 0.17 seconds.
>>
>> 6535
>> 6536 proc sort data=mylib.date9798 ;
>> 6537 by date1st ;
>> 6538 run ;
>>
>> NOTE: Input data set is already sorted, no sorting done.
>> NOTE: The PROCEDURE SORT used 0.05 seconds.
>>
>> 6539
>> 6540 data dates98 ;
>> 6541 set mylib.date9798 ;
>> 6542
>> 6543
>> 6544 format dob ddmmyy10. ;
>> 6545 informat dob ddmmyy10. ;
>> 6546
>> 6547 format ce_admit ddmmyy10. ;
>> 6548 informat ce_admit ddmmyy10. ;
>> 6549
>> 6550 format ce_disch ddmmyy10. ;
>> 6551 informat ce_disch ddmmyy10. ;
>> 6552
>> 6553 format date_sub ddmmyy10. ;
>> 6554 informat date_sub ddmmyy10. ;
>> 6555
>> 6556 format date1st ddmmyy10. ;
>> 6557 informat date1st ddmmyy10. ;
>> 6558
>> 6559>> 6563 if (crn="A77954") and (surname="UPHILL") and
>> (ce_admit='18OCT1997'd)
>> 6564 then date1st=.R ;
>> 6560 * If (CRN="A386117") and (surname="PEGLER") and
>> (ce_admit='12JAN98'd)
>> 6561 and (date1st=.) then date1st=99 ;
>> 6562
>> 6565
>> 6566 if (crn="A664468") and (surname="HILL") and
>> (ce_admit='02MAY1998'd)
>> 6567 then date1st=9 ;
>> 6568
>> 6569
>>
>> NOTE: The data set WORK.DATES98 has 421 observations and 7 variables.
>> NOTE: The DATA statement used 0.17 seconds.
>>
>> 6570 proc sort data=dates98 out=date9798 ;
>> 6571 by date_sub ;
>> 6572 run ;
>>
>> NOTE: The data set WORK.DATE9798 has 421 observations and 7
>> variables.
>> NOTE: The PROCEDURE SORT used 0.11 seconds.
>>
>> 6573
>> 6574 proc sort data=dates98 ;
>> 6575 by crn ;
>> 6576 run ;
>>
>> NOTE: The data set WORK.DATES98 has 421 observations and 7 variables.
>> NOTE: The PROCEDURE SORT used 0.16 seconds.
>>
>> 6577
>> 6578 proc contents data=dates98 ;
>> 6579 run ;
>>
>> NOTE: The PROCEDURE CONTENTS used 0.0 seconds.
>>
>> 6580
>> 6581 proc print data=dates98 ;
>> 6582 var crn surname ce_admit ce_disch date1st ;
>> 6583 where date1st^=. ;
>> 6584 run ;
>>
>> NOTE: The PROCEDURE PRINT used 0.05 seconds.
>>
>> Panos Papanikolaou
>> *********************
>> Research Fellow
>> Nursing, Health and Social Care Research Centre
>> SONWS
>> UWCM
>> Heath Park
>> Cardiff
>> CF14 4XN
>> Great Britain
>> E-mail: papanikolaoup@cf.ac.uk
>> Direct line: +44 (0)29 2074 2197
>> Fax: +44 (0)29 2074 5521
>
>--
>Lawrence H. ('Doc') Muhlbaier muhlb001@mc.duke.edu
>Assistant Research Professor
>Duke University Medical Center 919-668-8774 (office)
>DUMC 3865 919-383-0595 (home)
>Durham, NC 27710-7510 919-668-7057 (FAX)
Panos, try the trim function:
if (crn="A77954") and (trim(surname)="UPHILL") and
(ce_admit='18OCT1997'd)
then date1st=.R ;
This should help.
Dankwart Plattner
|