From: Hari on
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

From: Jim Groeneveld on
Hi Hari P.,

With put you can specify literal text, variables, formats and somewhat more,
but it is not an assignment expression, so you can't use the concatenation
operator || or !!.

Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
home.hccnet.nl/jim.groeneveld


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
From: Mike Rhoads on
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.

Mike Rhoads
Westat
RhoadsM1(a)Westat.com

-----Original Message-----
From: owner-sas-l(a)listserv.uga.edu [mailto:owner-sas-l(a)listserv.uga.edu]
On Behalf Of Hari
Sent: Tuesday, October 16, 2007 7:27 AM
To: sas-l(a)uga.edu
Subject: Functions in PUT statement


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
From: Hari on
On Oct 16, 5:30 pm, RHOAD...(a)WESTAT.COM (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.
>
> Mike Rhoads
> Westat
> Rhoad...(a)Westat.com
>
>
>
> -----Original Message-----
> From: owner-sa...(a)listserv.uga.edu [mailto:owner-sa...(a)listserv.uga.edu]
>
> On Behalf Of Hari
> Sent: Tuesday, October 16, 2007 7:27 AM
> To: sa...(a)uga.edu
> Subject: Functions in PUT statement
>
> 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- Hide quoted text -
>
> - Show quoted text -

Thanks Jim and Mike, that helps.

hp

From: Richard A. DeVenezia on
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


Unfortunately, the DATA Step does _not_ support Component Object attributes,
this will not compile...
put myHash.numItems=;

--
Richard A. DeVenezia
http://www.devenezia.com/