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 (August 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 21 Aug 2011 23:26:59 -0500
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: CALL EXECUTE help?
Comments: To: Vladimir Grechko <vlad.grechko@mail.ru>
In-Reply-To:  <CAM+YpE8sx=Kvk+NuOQze0Q+4pKWb9BAx4YNDD7o40r03VSTKCg@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

A birdie reminded me of the PUTN function, which more easily does what you want:

*data* have;

input treat $ trttype $ val;

cards;

A ACT 1.2345

A PLA 1.2345

B ACT 1.2345

B PLA 1.2345

;

*run*;

%let a_act = 8.1;

%let a_pla = 8.2;

%let b_act = 8.3;

%let b_pla = 8.4;

*proc* *format*;

value $numform

'A_ACT'='8.1'

'A_PLA'='8.2'

'B_ACT'='8.3'

'B_PLA'='8.4';

*quit*;

*data* want;

set have;

newval = putn(val,put(catx('_',treat,trttype),$NUMFORM.));

put newval=;

*run*;

On Sun, Aug 21, 2011 at 6:55 PM, Joe Matise <snoopy369@gmail.com> wrote:

> That's not what CALL EXECUTE does, basically... CALL EXECUTE runs code as > if it were in open code, so it doesn't do it inside a datastep. > > If you want to do that, you'd have to CALL EXECUTE a data step and set > statement, then a run statement afterwards. > > So: > data _null_; > set have end=end; > if _n_ = 1 then do; > call execute 'data want; set have;'; > end; > (your code); > if end then do; > call execute('run;'; > end; > run; > > However, I wouldn't say that's the best route to go in general... is this > exactly what you're doing, or is it more complicated than this? If this is > what you're doing, then you can do this a bunch of different ways. If > you're just using the values to determine the decimal point, then you can > ROUND to programmatically derived values. You could create an informat that > took 'A_ACT' as a value and returns 1, and then round or truncate to that > number of decimal places. That should give you the identical result to what > you're doing here (and then PUT it with BEST8. if you really want a char > variable). If it's more complex than that then let us know. > > -Joe > > On Sun, Aug 21, 2011 at 6:45 PM, Vladimir Grechko <vlad.grechko@mail.ru>wrote: > >> Sorry for a dumb question: >> >> I need to execute a macro based on the values of the variables in the >> dataset. What am i doing incorrectly here? >> >> Thank you in advance! >> Vlad >> >> data have; >> input treat $ trttype $ val; >> cards; >> A ACT 1.2345 >> A PLA 1.2345 >> B ACT 1.2345 >> B PLA 1.2345 >> ; >> >> %let a_act = 8.1; >> %let a_pla = 8.2; >> %let b_act = 8.3; >> %let b_pla = 8.4; >> >> %macro val_fmt (vfmt); >> newval = put(val, &vfmt); >> %mend; >> >> data need; >> set have; >> call execute ('%val_fmt(&' || strip(treat) || '_' || strip (trttype) || >> ')' ); >> run; >> >> LOG: >> NOTE: CALL EXECUTE generated line. >> NOTE: Line generated by the CALL EXECUTE routine. >> 1 + newval = put(val, 8.1); >> ------ >> 180 >> >> ERROR 180-322: Statement is not valid or it is used out of proper order. >> >> NOTE: Line generated by the CALL EXECUTE routine. >> 2 + newval = put(val, 8.2); >> ------ >> 180 >> > >


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