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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1120 views
  • 0 likes
  • 4 in conversation