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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2357 views
  • 0 likes
  • 4 in conversation