DATA Step, Macro, Functions and more

Error with parameter when used to assign a tbl name (used during create tbl

Reply
N/A
Posts: 0

Error with parameter when used to assign a tbl name (used during create tbl

Hello,

For some reason the symput variable I'm using won't work with a table name I'm creating. Is there any way around this?

ERROR 202-322: The option or parameter is not recognized and will be ignored.

ERROR 22-322: Syntax error, expecting one of the following: (, AS, LIKE.



libname t '/sas/userdata/mine';

data _null_;
tod_date = date();
call symput('todaydate', tod_date);
run;

proc sql;
create table t.rec_m_list&todaydate as
select * from t.data_table;
quit;
Super Contributor
Super Contributor
Posts: 3,174

Re: Error with parameter when used to assign a tbl name (used during create tbl

Posted in reply to deleted_user
Reply again with a complete SAS log, using the additional OPTIONS statement, which may help self-diagnose the error:

OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT;

Scott Barry
SBBWorks, Inc.
Valued Guide
Posts: 2,177

Re: Error with parameter when used to assign a tbl name (used during create tbl

Posted in reply to deleted_user
> Hello,
>
> For some reason the symput variable I'm using won't
> work with a table name I'm creating. Is there any way
> around this?
>
> ERROR 202-322: The option or parameter is not
> recognized and will be ignored.
>
> ERROR 22-322: Syntax error, expecting one of the
> following: (, AS, LIKE.
>
>
>
> libname t '/sas/userdata/mine';
>
> data _null_;
> tod_date = date();
> call symput('todaydate', tod_date);
> run;
>
> proc sql;
> create table t.rec_m_list&todaydate as
> select * from t.data_table;
> quit;

ScottP1
it is obvious (once you know 15 answers - obvious millionaire time ;-) too )
So remember that macro variables are strings, so
> call symput('todaydate', tod_date);
converts the value in tod_date to a string with default conversion.
Better in SAS9 is symputX() which suppresses the NOTE about numeric to character conversion and removes leading and trailing blanks from the value pushed into the macro variable 'todaydate'.
Your problem was probably caused by leading blanks in the value in &todaydate.

Another issue might strike you once you solve that leading blank problem.
The value is just a number, because sas supports dates by storing them as a number and providing a wealth of formats to present dates.
So, table t.rec_m_list&todaydate would become something like t.rec_m_list18362 on 10-Apr-2010.
If you wanted t.rec_m_list20100410, you could use
>> call symput('todaydate', put(tod_date, yymmddN8.) );
That put() function creates a date string just 8 digits wide, so no blanks.

but I wouldn't use nor recommend a datastep for this kind of thing.
Are you ready for %sysfunc() ? Check it out in on the sas support web site. Here is my take on achieving what you seem to seek

%let todayDate = %sysfunc( date(), yymmddN8 );
> proc sql;
> create table t.rec_m_list&todaydate as
> select * from t.data_table;
> quit;
Alternative formats have inconveniences like not sorting well when a list of these tables is sorted by name, or containing invalid characters like /

have a look at call symputX() and %sysfunc(). Not only do I think you'll find it informative. I think you'll come up with even better ways to use these features.

Look forward to hearing more from you ScottP1, demonstrating new found learning.

PeterC
Ask a Question
Discussion stats
  • 2 replies
  • 166 views
  • 0 likes
  • 3 in conversation