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

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

1 ACCEPTED SOLUTION

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

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

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Astounding
PROC Star

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.

ballardw
Super User

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.

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