DATA Step, Macro, Functions and more

find numbers from string in macro

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

find numbers from string in macro

Hi  All,

 

I have data as below.

 

Values

 

LAB_RESULT1

LAB_UNITS

LAB_HI1

 

I want to find out the string which contain numbers at any position in string.

 

I need the same in macro only and in macro anydigit is not working for me.

 

Regards,

Rajesh


Accepted Solutions
Solution
‎09-28-2016 11:59 AM
Super User
Super User
Posts: 7,407

Re: find numbers from string in macro

Yes, anydigit() will not work straight off, you could put it in %sysfunc(), but that has limited functions it supports.  The simple point here is the Macro language is NOT the programming language.  It is a text generation tool.  Base SAS is THE programming language, it has all the data types, the functions, the procedures.  Use the right tool for the right job, you wouldn't believe how many questions take the form "Have to use macro, not working", and the answer is always use Base SAS.  If you abosultely have to have the string in macro then:

data _null_;
  if anydigit("&VALUE.") then res=1;
  else res=0;
  call symput('res',res);
run;

...
%if &res. %then %do;
...

This combines Base SAS step with macro variables.

View solution in original post


All Replies
Solution
‎09-28-2016 11:59 AM
Super User
Super User
Posts: 7,407

Re: find numbers from string in macro

Yes, anydigit() will not work straight off, you could put it in %sysfunc(), but that has limited functions it supports.  The simple point here is the Macro language is NOT the programming language.  It is a text generation tool.  Base SAS is THE programming language, it has all the data types, the functions, the procedures.  Use the right tool for the right job, you wouldn't believe how many questions take the form "Have to use macro, not working", and the answer is always use Base SAS.  If you abosultely have to have the string in macro then:

data _null_;
  if anydigit("&VALUE.") then res=1;
  else res=0;
  call symput('res',res);
run;

...
%if &res. %then %do;
...

This combines Base SAS step with macro variables.

Super User
Posts: 5,085

Re: find numbers from string in macro

You will need to find a new plan.

 

Macro language does not process values within a SAS data set.  You would have to first create a set of macro variables from the data values, and then macro language could examine them one by one.

Super User
Posts: 10,516

Re: find numbers from string in macro

And to add to @Astounding's very important comment, you would have to multiple the complexity severely if there are other pieces of information needed such as the values of other variables.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 227 views
  • 0 likes
  • 4 in conversation