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

Hi,

 

data data1;

input val_pas $20. ;

infile datalines truncover;

datalines;

substring\_'

;

run;

 

data data2;

input func $60. ;

infile datalines truncover;

datalines;

prxchange('s/[^0-9a-zA-Z.&_,\\\-\''\[\]\(\)\s]/^/', -1, val_pas)

;

run;

data output;

set data1 data2;

out_value=func;

run;

******************************************************************************

I want to call prxchange function and assign the out put to variable "out_value". For this function  "val_pas" is one of the parameter(data1=Source text for regular expresion matching).

 

Is there any way to execute the function ?

 

Many thanks.

 

Regards

Hari.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, you can create code using the call execute function:

data _null_;
  set data2;
  call execute('data output; set data1; out_value='||strip(func)||'; run;');
run;

You will need to read up on the call execute function, it is very powerfull, but you do need to know how to use it.

View solution in original post

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, you can create code using the call execute function:

data _null_;
  set data2;
  call execute('data output; set data1; out_value='||strip(func)||'; run;');
run;

You will need to read up on the call execute function, it is very powerfull, but you do need to know how to use it.

K_HARI__PRASAD
Calcite | Level 5
Hi Super User,

Thanks for your answer. But I am getting an unknown error as below.

+ data output; set data1; out_value=prxchange('s/[^0-9a-zA-Z.&_,\-\''\[\]\(\)\s]/^/', -1, val_pa; run;
_
79

ERROR 79-322: Expecting a ).
Astounding
PROC Star

That error is related to a flaw in your original program.  The length of $60 is not long enough to hold the value that you are trying to read in.  Correct the length and try again.

K_HARI__PRASAD
Calcite | Level 5
Hi RW9,

Could you please provide some links to read about Call Execute function.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, top three google responses:

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543697.htm

http://www2.sas.com/proceedings/sugi22/CODERS/PAPER70.PDF

http://www2.sas.com/proceedings/sugi22/CODERS/PAPER86.PDF

 

Once you understand the concept its pretty simple and powerful.  Basically the call execute takes a string, which inserted into the code stream after the datastep executing has finished.  That text string will be considered code and compiled as any other code.

K_HARI__PRASAD
Calcite | Level 5
Thank you so much 🙂

##- Please type your reply above this line. Simple formatting, no
attachments. -##
data_null__
Jade | Level 19

While the PRXCHANGE function does need to be compiled (i.e. can't be an expression) the arguments to the function can be expressions.  

 

http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#n0r8h2fa8dj...

Astounding
PROC Star

I believe that this is one of the uses for the RESOLVE function:

 

out_value = resolve(func);

 

It's untested, but I think it does what you're asking.

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