BookmarkSubscribeRSS Feed
Lucas
Calcite | Level 5
Hi all!

Cynthia@sas

Yes, I want to achieve exactly what you think.
I don't just want to see the text string with the INTNX function in the new column, I want to have the INTNX function execute.

Another words:

If I have oryginal DataSet
col_EXP;
intnx('day',today(),2);
intnx('day',today(),10);

I want to achieve this result:
col_EXP;col_DT
intnx('day',today(),2); 2010-12-09
intnx('day',today(),10); 2010-12-17


The solution of @art297, @polingjw and @Ksharp works fine. I was just wondered if it can be done in easier way. Now I know that there is no chance to make this in one datastep.
art297
Opal | Level 21
Lucas,

I posted your question on the SAS-L board and one if its members, Joe Matise, provided precisely what I think you were looking for. Take a look at the following:

DATA test;
length col_EXP $50;
col_EXP="intnx(day,%sysfunc(today()),2)";output;
col_EXP="intnx(day,%sysfunc(today()),10)";output;
RUN;


data want;
set test;
format col_DT date9.;
col_DT = resolve('%sysfunc('||col_exp||')');
run;

Also, you had asked me about the formatting of the put statements I had used in my original offering. The +3 was simply indenting the line so that the file would be easier to read by humans.

Art
Lucas
Calcite | Level 5
art297,

Yes, it is exactly what I was looking for 🙂 Thanks a lot!

P.S What is SAS-L board? I'm quite new in SAS...
art297
Opal | Level 21
A description of SAS-L, and how to access it, can be found at:
http://www.sascommunity.org/wiki/SAS-L

Art
Lucas
Calcite | Level 5
Thanks!
The problem was solved perfectly.
Ksharp
Super User
Hi.
The code is very brilliant.
But your code has some little different with op's code.

[pre]
col_EXP="intnx('day',today(),2)";output;
col_EXP="intnx(day,%sysfunc(today()),2)";output;
[/pre]

When I add two ' into your code ,and I got Error.


[pre]
364 data want;
365 set test;
366 format col_DT date9.;
367 col_DT = resolve('%sysfunc('||col_exp||')');
368 run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
367:10
ERROR: Required operator not found in expression: today()
ERROR: Argument 2 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or
%QSYSFUNC function reference is terminated.
ERROR: Required operator not found in expression: today()
ERROR: Argument 2 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or
%QSYSFUNC function reference is terminated.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 2 observations read from the data set WORK.TEST.
WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 2 observations and 2 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.00 seconds


[/pre]



Ksharp

Message was edited by: Ksharp
ArtC
Rhodochrosite | Level 12
Ksharp If you try only the second assignment statement the code will work. As with so many things in the macro language it is all about the timing.
Ksharp
Super User
Call execute can do it.It is very powerful.

[pre]
DATA test;
length col_EXP $50;
col_EXP="intnx('day',today(),2)";output;
col_EXP="intnx('day',today(),10)";output;
RUN;
data _null_;
set test end=last;
if _n_ eq 1 then call execute('data result;');
call execute('col_EXP=" '||col_EXP||'" ; ' );
call execute(cats('col_DT=',col_EXP,';' ));
call execute('format col_DT date9. ;');
call execute('output;');
if last then call execute('run;');
run;
[/pre]



Ksharp

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
  • 22 replies
  • 3427 views
  • 0 likes
  • 8 in conversation