Date: Mon, 22 Aug 2011 12:15:22 -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?
In-Reply-To: <201108221630.p7MF2Og1017117@waikiki.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
You should still be able to use PUTN then, I was just using PROC FORMAT to
create the relationship between a_pla and 8.1. Whatever dynamic method you
define that relationship in CALL EXECUTE can identically be used either by
PROC FORMAT or something else to drive the PUTN function. I think you can
basically just plug in PUTN where you use CALL EXECUTE and have the same
result.
-Joe
On Mon, Aug 22, 2011 at 11:30 AM, Vladimir Grechko <vlad.grechko@mail.ru>wrote:
> Thank you, Joe!
>
> Unfortunately, I cannot use proc format: there are more choices
> than I presented in my simple example. The values of a_pla, b_act, etc.,
> that i listed in %let statement(s) are created dynamically. That's why I
> was thinking about CALL EXECUTE. But i am not sure about the timing of its
> execution: it seems that only the value of the last of the four %LET gets
> applied in the code that I presented as an example, although the log shows
> that all four get resolved:
>
> data _null_;
> set have end=end;
> if _n_ = 1 then do;
> call execute ('data want; set have;');
> *call execute ('%val_fmt(&' || strip(treat) || '_' || strip (trttype)
> || ')' ); *<-- everything is 8.1;
> end;
> call execute ('%val_fmt(&' || strip(treat) || '_' || strip (trttype) ||
> ')' ); *<-- everything is 8.4;
> if end then do;
> call execute('run;');
> end;
> run;
>
>
>
> On Sun, 21 Aug 2011 23:26:59 -0500, Joe Matise <snoopy369@GMAIL.COM>
> wrote:
>
> >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
> >>>
> >>
> >>
>
|