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 😉
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.
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.
So stupid! ^^
Thanks Astounding!
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;
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.
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.