From: "Howard Schreier <hs AT dc-sug DOT org>" on
On Tue, 16 Oct 2007 04:26:30 -0700, Hari <excel_hari(a)YAHOO.COM> wrote:

>Hi,
>
>I was working through CALL SYMPUT and SYMGET in online learning and
>wanted to see whether the values assigned during a CALL SYMPUT can be
>seen in a new data step utilizing SYMGET statement.
>
>Options symbolgen;
>data null_;
> set sasuser.schedule;
>call symput('same_val', 'Hallis, Dr. George');
>call symput(compress('current_val'|| _n_), teacher);
>run;
>
>Data _null_;
>Set null_;
>MacroVarName = "current_val"|| left(_n_);
>MacroVarValue = symget(MacroVarName);
>Put 'MacroVarName:' MacroVarName 'MacroVarValue:' MacroVarValue;
>Run;
>
>The above worked perfectly fine.
>
>But, if I modify the second data step
>
>Data _null_;
>Set null_;
>/*MacroVarName = "current_val"|| left(_n_);*/
>/*MacroVarValue = symget(MacroVarName);*/
>Put 'MacroVarName:' "current_val"|| left(_n_) 'MacroVarValue:'
>symget(MacroVarName);
>Run;
>
>The i get error in put statement
>
>274 Data _null_;
>275 Set null_;
>276 /*MacroVarName = "current_val"|| left(_n_);*/
>277 /*MacroVarValue = symget(MacroVarName);*/
>278 Put 'MacroVarName:' "current_val"|| left(_n_) 'MacroVarValue:'
>symget(MacroVarName);
> -- ----------------
> 22 79
> 76
> ----
> 202
>ERROR 22-322: Syntax error, expecting one of the following: a name, a
>quoted string, arrayname,
> #, (, +, /, //, ;, @, @@, OVERPRINT, _ALL_, _BLANKPAGE_,
>_ODS_, _PAGE_.
>
>ERROR 79-322: Expecting a (.
>
>ERROR 76-322: Syntax error, statement will be ignored.
>
>ERROR 202-322: The option or parameter is not recognized and will be
>ignored.
>
>279 Run;
>
>I have tried with core data step functions within PUT and even those
>are failing. I did a very quick read through the SAS documentation for
>PUT, but not able to see any restrictions on using SAS function in
>PUT?
>
>Please guide me
>
>hp

The capabilities of the PUT statement have already been discussed, but let's
look at the documentation question which Hari asked.

The doc does not express a restriction concerning specification of functions
(or, more generally, expressions) because there is nothing in the doc which
implies that functions are permitted. See

Base SAS
SAS Language Reference: Dictionary
Dictionary of Language Elements
Statements
PUT Statement
Arguments
specification

It's interesting that the PUT statement is able to invoke evaluation of
expressions; specifically, numeric expressions, contained in parentheses,
are allowed as pointer controls.
From: Chang Chung on
On Tue, 16 Oct 2007 11:32:12 -0400, Richard A. DeVenezia
<rdevenezia(a)WILDBLUE.NET> wrote:

>Mike Rhoads wrote:
>> Although it would be nice if PUT supported functions, expression
>> evaluation, etc., it basically is limited to putting out (1) variable
>> values, and (2) constant text. It has an incredible amount of
>> flexibility within those constraints (for instance, NAMED output to
>> include the names of variables and limited expression evaluation to
>> determine where to put things), but that's as far as it goes.
>
>The PUT statment in SAS Component Language supports object attributes and
>methods -- it even supports the = specifier
>
>main:
>...
> declare sasuser.objects.foo foo = _new_ sasuser.objects.foo();
> put foo.someMethod1() foo.someMethod2()= foo.attribute1;
>...
>return;
>===log===
>ThisIsReturnedFromMethod1 foo.someMethod2()=ThisWasReturnedFromMethod2
>footribute1

hi,

in addition to PUT in data step, PUT in SCL, there is PUT in the sas
function compiler in sas/base (proc fcmp), which *is* able to handle
expressions (inside of parentheses) but otherwise much crippled compare to
the data step's:

/*
see p.14 of the online doc for the limitations of put in proc fcmp
http://support.sas.com/documentation/onlinedoc/base/91/fcmp.pdf
*/
proc fcmp;
x = 2;
put (sqrt(x));
run;
/* on lst
1.4142135624
*/

There is also the PUT in proc template, which also supports calling any data
step functions and has interesting syntax of:
(from http://support.sas.com/rnd/base/topics/odsmarkup/tagsets.html)

PUT | PUTL | PUTQ (<variable> <String> <function> <nl|cr|lf> )* <conditon>;

Now, I am wondering about 9.2 data step PUT statement. Do you know if there
are any changes on it?

Cheers,
Chang