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

Seems simple enough –  An hour later and various attempts, no further forward, so bow to the experts:-

 

Data _Null_;
     call symputx('C_Time',%sysfunc(time(),timeampm.));
     %put The current time is &=C_Time;
     %put The Non-macro time is %sysfunc(time(),timeampm.);
Run;

 

Excerpt from the Log

 

33       !  Data _Null_;
34                   call symputx('C_Time',%sysfunc(time(),timeampm.));
NOTE: Line generated by the macro function "SYSFUNC".
34         11:43:04 AM
             _
             388
             200
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

35                   %put The current time is &=C_Time;
WARNING: Apparent symbolic reference C_TIME not resolved.
The current time is C_Time
36                   %put The Non-macro time is %sysfunc(time(),timeampm.);
The Non-macro time is 11:43:04 AM
37              Run;

Even if I wrap the second argument with a Put to specifically convert Numeric to Character – same result.

 

What is the answer?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

The second argument to the call symput routine must be a string, so use double quotes.

And move the %put statements after the run, as they would otherwise be resolved before the data step runs, and throw an error.

Data _Null_;
call symputx('C_Time',"%sysfunc(time(),timeampm.)");
Run;

%put The current time is &=C_Time;
%put The Non-macro time is %sysfunc(time(),timeampm.);

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

The second argument to the call symput routine must be a string, so use double quotes.

And move the %put statements after the run, as they would otherwise be resolved before the data step runs, and throw an error.

Data _Null_;
call symputx('C_Time',"%sysfunc(time(),timeampm.)");
Run;

%put The current time is &=C_Time;
%put The Non-macro time is %sysfunc(time(),timeampm.);
andreas_lds
Jade | Level 19

If you are inside a macro, then using

%let C_Time = %sysfunc(time(),timeampm.);

should solve the problem. If you want to use a data step, replacing %sysfunc with

 call symputx('C_Time', put(time(),timeampm.));

should be all you need.

Tom
Super User Tom
Super User

You seem a little confused about what the macro processor does and when it does it.  It modifies the code and passes on to SAS to execute.  So your %PUT statements in the middle of a data step will execute BEFORE the data step executes.

 

You could either use macro code to make your macro variable.

%let C_Time=%sysfunc(time(),timeampm.);
%put The current time is &=C_Time;

Or use SAS code to make the macro variable.

data _null_;
  now=time();
  put 'The Non-macro time is ' now timeampm.;
  call symputx('C_Time',put(now,timeampm.));
run;

If you did want to use the value of the macro variable to generate some SAS code them make sure it is generating valid SAS code.

data _null_;
  put "The value of C_TIME is &c_time".
run;
Brunts23
Calcite | Level 5

I'm slowly completing the Advanced SAS training and trying to work things out in my head as to what works and why - Thanks for the input

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
  • 4 replies
  • 906 views
  • 1 like
  • 4 in conversation