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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.;

View solution in original post

7 REPLIES 7
WarrenKuhfeld
Rhodochrosite | Level 12

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.

Julia22
Fluorite | Level 6

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

 

 

 

 

 

 

Julia22
Fluorite | Level 6

Thank you that worked

Tom
Super User Tom
Super User

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.;
Julia22
Fluorite | Level 6

Thank you that worked 🙂

Julia22
Fluorite | Level 6
Hi ,
Above one solves for date how to create variables for other two

count&&Rcc_pp = Symget(‘s_cnt&&Rcc’);
V&&Rcc_time = symget(‘Processing_timev&&Rcc’);
Kurt_Bremser
Super User

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 3846 views
  • 3 likes
  • 4 in conversation