LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (May 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 24 May 2011 15:07:01 -0400
Reply-To:     Nat Wooding <nathani@VERIZON.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Nat Wooding <nathani@VERIZON.NET>
Subject:      Re: Simple SAS Problem
Comments: To: vaibhav wadhera <vaibhavwadhera@GMAIL.COM>
In-Reply-To:  <BANLkTikUS-aUaxoNRqrf06HKjuGfsBOFeA@mail.gmail.com>
Content-Type: text/plain; charset="US-ASCII"

Vaibhav

Your problem is that you retain the values of TYPE_NR_MEDICAL and OPT_NR_MEDICAL so they carry over from one value of PRSN_ID to the next. Hence, you need to reset them at the start of each PRSN_ID or change your if statements to If ... then ...;else ...

The following code simply resets each of them.

Nat Wooding

DATA LOW; SET HIGH; BY PRSN_ID TYPE_NR; RETAIN TYPE_NR_MEDICAL OPT_NR_MEDICAL ; IF FIRST.PRSN_ID THEN DO; Type_NR_Medical = '';** reset these two variables at the start of each PRSN_ID; Opt_NR_Medical = ''; IF TYPE_NR = '01' THEN TYPE_NR_MEDICAL = TYPE_NR;

IF OPT_NR = '02' THEN OPT_NR_MEDICAL = OPT_NR ; END; IF LAST.PRSN_ID THEN DO; IF TYPE_NR= '02' THEN TYPE_NR_DENTAL = TYPE_NR; IF OPT_NR = '03' THEN OPT_NR_DENTAL = OPT_NR ; OUTPUT LOW; END;

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of vaibhav wadhera Sent: Tuesday, May 24, 2011 2:23 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Simple SAS Problem

Hi

I have following code

DATA HIGH; INPUT PRSN_ID TYPE_NR $ OPT_NR $; DATALINES; 991 01 02 991 02 03 992 01 02 993 02 03 ; RUN;

PROC SORT DATA=HIGH; BY PRSN_ID TYPE_NR; RUN;

DATA LOW; SET HIGH; BY PRSN_ID TYPE_NR; IF FIRST.PRSN_ID THEN DO; RETAIN TYPE_NR_MEDICAL OPT_NR_MEDICAL ;

IF TYPE_NR = '01' THEN TYPE_NR_MEDICAL = TYPE_NR; IF OPT_NR = '02' THEN OPT_NR_MEDICAL =OPT_NR; END; IF LAST.PRSN_ID THEN DO; IF TYPE_NR= '02' THEN TYPE_NR_DENTAL= TYPE_NR; IF OPT_NR = '03' THEN OPT_NR_DENTAL =OPT_NR; OUTPUT LOW; END;

PROC PRINT DATA=LOW; RUN;

And the results i am getting are TYPE_NR_ OPT_NR_ TYPE_NR_ OPT_NR_ Obs PRSN_ID TYPE_NR OPT_NR MEDICAL MEDICAL DENTAL DENTAL

1 991 02 03 01 02 02 03 2 992 01 02 01 02 3 993 02 03 01 02 02 03 -- But i need

TYPE_NR_ OPT_NR_ TYPE_NR_ OPT_NR_ Obs PRSN_ID TYPE_NR OPT_NR MEDICAL MEDICAL DENTAL DENTAL

1 991 02 03 01 02 02 03 2 992 01 02 01 02 3 993 02 03 02 03

Please have a look

Thanks & Regards

Vaibhav wadhera


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