DATA Step, Macro, Functions and more

Symput not resolved

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

Symput not resolved

[ Edited ]

Hi all,

 

I try to do something easy, it's not working.

So frustrating!

 

data _null_;
call symput('EXECTIME', time());
put &EXECTIME.;
run;

The mistake is:

WARNING: Apparent symbolic reference EXECTIME not resolved.

And for the put line:

ERROR 22-322: Expecting a name.

What is wrong with this??

 

Thank you for your help Smiley Wink

 


Accepted Solutions
Solution
‎03-01-2017 02:43 PM
Super User
Posts: 5,497

Re: Symput not resolved

In SAS, as in life, timing is everything.

 

The software examines the statements within the DATA step, performing any set-up work and checking for syntax errors.  It does this before actually executing the DATA step, and before executing CALL SYMPUT.  Therefore, the software comes up with a syntax error in the PUT statement, since the macro variable has not yet been created.  An alternative version:

 

data _null_;

call symputx('EXECTIME', time());

run;

%put &EXECTIME.;

 

Also note how switching to CALL SYMPUTX gets rid of any messages about numeric to character conversion.

View solution in original post


All Replies
Solution
‎03-01-2017 02:43 PM
Super User
Posts: 5,497

Re: Symput not resolved

In SAS, as in life, timing is everything.

 

The software examines the statements within the DATA step, performing any set-up work and checking for syntax errors.  It does this before actually executing the DATA step, and before executing CALL SYMPUT.  Therefore, the software comes up with a syntax error in the PUT statement, since the macro variable has not yet been created.  An alternative version:

 

data _null_;

call symputx('EXECTIME', time());

run;

%put &EXECTIME.;

 

Also note how switching to CALL SYMPUTX gets rid of any messages about numeric to character conversion.

Contributor
Posts: 42

Re: Symput not resolved

Posted in reply to Astounding

So stupid! ^^

 

Thanks Astounding!

Valued Guide
Posts: 505

Re: Symput not resolved

You ar enot stupid

Here are a few solutions

data _null_;
   call symput('EXECTIME', put(time(),hhmm5.));
   time=symget('exectime');
   put time=;
run;quit;


%symdel exectime;
data _null_;
if _n_=0 then do;
  %let rc=%sysfunc(dosubl('
     %let exectime=%sysfunc(putn(%sysfunc(time()),HHMM5.));
     '));
  end;
  put "&EXECTIME.";
run;

11:43

%symdel exectime;
data _null_;
  if _n_=0 then do;
    %let rc=%sysfunc(dosubl('
      proc sql;
         select put(time(),hhmm.) into :exectime from sashelp.class(obs=1)
      ;quit;
    '));
  end;
  put "&exectime";
run;quit;

%symdel exectime;
data _null_;
  if _n_=0 then do;
    %let rc=%sysfunc(dosubl('
      data _null_;
         call symputx("EXECTIME", put(time(),hhmm5.),'G');
      ;run;
    '));
  end;
  put "&exectime";
run;quit;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 139 views
  • 2 likes
  • 3 in conversation