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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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