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 (April 2008, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 15 Apr 2008 10:26:07 -0400
Reply-To:     Paul Dorfman <sashole@BELLSOUTH.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Dorfman <sashole@BELLSOUTH.NET>
Subject:      Re: need help in coding this...
Comments: To: SUBSCRIBE SAS-L Cherish <hawks_cherish@YAHOO.CO.IN>

Mark,

In

>data _null_; >dsid=open('test',"i"); >n_obs=attrn(dsid,"nobs"); >call symput("n_obs",n_obs); >run;

you left the file open, which is tantamount to troubling a trouble. Also, would it not be simpler to just

data _null_ ; call symputx ('n', n) ; stop ; set test n = nobs ; run ;

Note the use of symputX avoiding the type conversion note.

Kind regards ------------ Paul Dorfman Jax, FL ------------ Don't shoot my pizza.

On Tue, 15 Apr 2008 12:09:11 +0100, cherish k <hawks_cherish@YAHOO.CO.IN> wrote:

>Please find the code. > >drop the min and max values from the final dataset separately. > >data test; >input f1 f2; >datalines; >1 4 >1 3 >2 2 >4 4 >4 5 >; >run; > >data _null_; >dsid=open('test',"i"); >n_obs=attrn(dsid,"nobs"); >call symput("n_obs",n_obs); >run; > > >%macro chk; > >%do i = 1 %to &n_obs; > data test; > set test; > if _n_ eq %eval(&i) then do; > min_val = min(f1,f2); > max_val = max(f1,f2); > end; > if min_val ne . and max_val ne . and f1 = max_val then f1 = min_val; > if min_val ne . and max_val ne . and f2 = max_val then f2 = min_val; > retain min_val max_val; > run; >%end; > >%mend; > >%chk; > >Cherish > >Mark Marquez <sickpurple@GMAIL.COM> wrote: hi, i have a problem in coding the following scenario... > >Given the following data set w/ 5 obs (the # of iterations will be equal to >the # of obs): >f1, f2 >1, 4 >1, 3 >2, 2 >4, 4 >4, 5 > >1st iteration--point to obs 1 (f1=1, f2=4); get the minimum between f1 & f2 >(min=1) for the current obs; update starting from the current obs (obs 1) >until the last obs for all occurrences of the higher value between f1 & f2 >(4) set equal to the minimum (1) >f1, f2 >1, 4-->1 >1, 3 >2, 2 >4-->1, 4-->1 >4-->1, 5 > >2nd iteration--point to obs 2 (f1=1, f2=3); get the minimum between f1 & f2 >(min=1) for the current obs; update starting from the current obs (obs 2) >until the last obs for all occurrences of the higher value between f1 & f2 >(3) set equal to the minimum (1) >f1, f2 >1, 1 >1, 3-->1 >2, 2 >1, 1 >1, 5 > >3rd iteration--point to obs 3 (f1=2, f2=2); skip; no update needed since >both are equal >f1, f2 >1, 1 >1, 1 >2, 2 >1, 1 >1, 5 > >4th iteration--point to obs 4 (f1=1, f2=1); skip; no update needed since >both are equal >f1, f2 >1, 1 >1, 1 >2, 2 >1, 1 >1, 5 > >5th & last iteration--point to obs 5 (f1=1, f2=5); get the minimum between >f1 & f2 (min=1) for the current obs; update the current obs (obs 5) for the >occurrence of the higher value between f1 & f2 (5) set equal to the minimum (1) >f1, f2 >1, 1 >1, 1 >2, 2 >1, 1 >1, 5-->1 > >Final data set--yes, both f1 & f2 will end up having the same values: >f1, f2 >1, 1 >1, 1 >2, 2 >1, 1 >1, 1 > > > between 0000-00-00 and 9999-99-99 <!--11--><hr size=1></hr> Best Jokes, Best Friends, Best Food. Get all this and more on <a href="http://in.rd.yahoo.com/tagline_groups_11/*http://in.promos.yahoo.com/ groups/bestofyahoo/"> Best of Yahoo! Groups.</a>


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