BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fabdu92
Obsidian | Level 7

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 😉

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

3 REPLIES 3
Astounding
PROC Star

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.

fabdu92
Obsidian | Level 7

So stupid! ^^

 

Thanks Astounding!

rogerjdeangelis
Barite | Level 11
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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