Hi ,
I am calculating Processing , start time and count of nid and wanted to get them into dataset sas
%let Rcc = 66;
%let ty=p;
%let datetime_start = %sysfunc(TIME());
%let START_TIME_WITHV&&Rcc = %sysfunc(datetime(),datetime14.);
%put &&START_TIME_WITHV&Rcc;
data scores;
infile datalines truncover;
input nid $ 1-12 score2 17-20 score1 27-30;
datalines;
Riley 1132 987
Henderson 1015 1102
;
%let END_TIME_WITH_V&&Rcc= %sysfunc(datetime(),datetime14.);
%put &&END_TIME_WITH_V&Rcc;
%let PROCESSING_TIMEV&&Rcc= %sysevalf(%sysfunc(TIME())-&datetime_start.);
%put &&PROCESSING_TIMEV&Rcc;
proc contents data= scores out=ty_contents;
run;
proc sql noprint;
select name into :score_t_&&Rcc
from ty_contents
where prxmatch("s/nid//i",name);
select count(distinct &&score_t_&Rcc) into :s_cnt&&Rcc from scores(keep=&&score_t_&Rcc);
quit;
%put &&score_t_&Rcc &&s_cnt&Rcc;
/*count , start time and processing time variables into dataset */
data test5;
Date = SYMGET('START_TIME_WITHV&&Rcc');
length count&&Rcc_pp 3;
length V&&Rcc_Runtime 8;
count&&Rcc_pp = SYMGET('s_cnt&&Rcc');
V&&Rcc_time=SYMGET('PROCESSING_TIMEV&Rcc');
format V&&Rcc_time TIME11.2;
run;
How to get Date into test5 and also , how to get count into dataset , how to get processing time into test5 dataset
Can anyone please help
Thanks
The SAS LOG should show a pretty clear error message.
11 %let Rcc = 66; 12 %let START_TIME_WITHV&&Rcc = %sysfunc(datetime(),datetime14.); 13 %put &&START_TIME_WITHV&Rcc; 09DEC17:20:39 14 data _null_; 15 x1=symget('START_TIME_WITHV&Rcc'); 16 put x1=; 17 run; INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation can result. 15:3 x1 ERROR: Symbolic variable name START_TIME_WITHV&RCC must contain only letters, digits, and underscores. NOTE: Invalid argument to function SYMGET('START_TIME_W'[12 of 20 characters shown]) at line 15 column 6. x1= x1= _ERROR_=1 _N_=1 NOTE: The SAS System stopped processing this step because of errors.
The SYMGET() function wants the NAME of the macro variable, but macro variable names cannot contain &. If you want the &RCC suffix to be evaluated so that SYMGET() can use the actual macro variable's name then you must use double quotes instead of single quotes.
symget("START_TIME_WITHV&Rcc")
But then again why use SYMGET()? There is nothing in the data step that is changing the value of the macro variable.
Date = "&&START_TIME_WITHV&&Rcc";
If you want DATE to be a number and not a character string then perhaps you want to use a datetime literal?
Date = "&&START_TIME_WITHV&&Rcc"dt;
format date datetime14.;
Of course if want the real value then do not generate the value using the DATETIME14 format since that will lose precision.
Instead leave it as the raw number of seconds.
%let START_TIME_WITHV&&Rcc = %sysfunc(datetime());
.....
Date = &&START_TIME_WITHV&&Rcc;
format date datetime20.;
Macro variables are not resolved within single quotes. Use double quotes if you want macro variables to resolve. I did not try to understand your program, but I noticed that much.
I want to get these values 'START_TIME_WITHV&&Rcc' , 's_cnt&&Rcc' , 'PROCESSING_TIMEV&Rcc' into datastep
and create these variables Date , count&&Rcc_pp and V&&Rcc_time respectively in a dataset test5
Can u please help
Thank you that worked
The SAS LOG should show a pretty clear error message.
11 %let Rcc = 66; 12 %let START_TIME_WITHV&&Rcc = %sysfunc(datetime(),datetime14.); 13 %put &&START_TIME_WITHV&Rcc; 09DEC17:20:39 14 data _null_; 15 x1=symget('START_TIME_WITHV&Rcc'); 16 put x1=; 17 run; INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation can result. 15:3 x1 ERROR: Symbolic variable name START_TIME_WITHV&RCC must contain only letters, digits, and underscores. NOTE: Invalid argument to function SYMGET('START_TIME_W'[12 of 20 characters shown]) at line 15 column 6. x1= x1= _ERROR_=1 _N_=1 NOTE: The SAS System stopped processing this step because of errors.
The SYMGET() function wants the NAME of the macro variable, but macro variable names cannot contain &. If you want the &RCC suffix to be evaluated so that SYMGET() can use the actual macro variable's name then you must use double quotes instead of single quotes.
symget("START_TIME_WITHV&Rcc")
But then again why use SYMGET()? There is nothing in the data step that is changing the value of the macro variable.
Date = "&&START_TIME_WITHV&&Rcc";
If you want DATE to be a number and not a character string then perhaps you want to use a datetime literal?
Date = "&&START_TIME_WITHV&&Rcc"dt;
format date datetime14.;
Of course if want the real value then do not generate the value using the DATETIME14 format since that will lose precision.
Instead leave it as the raw number of seconds.
%let START_TIME_WITHV&&Rcc = %sysfunc(datetime());
.....
Date = &&START_TIME_WITHV&&Rcc;
format date datetime20.;
Thank you that worked 🙂
Several issues here.
Since you omitted a
run;
to end your data step, the %let's that should determine the execution time are resolved before the data step runs, so you'll get no time at all.
The data step itself will execute so quickly that you will have to look for fractions of a second.
In the final data step, your symget can't work because of the single quotes that prevent the resolution of &rcc.
And if you want to reference a macro variable inside a word, you MUST use a dot to end the reference, like
count&rcc._pp
, or SAS will look for a macro variable rcc_pp, which was never defined. Bottom line: always end a macro variable reference with a dot, it's never wrong and always helpful.
And be more consistent with your use of single and double ampersands, to make code more readable. Double ampersands are only needed when you refer indirectly and need two passes of the macro resolver.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.