BookmarkSubscribeRSS Feed
SASuserlot
Lapis Lazuli | Level 10

I am trying to resolve the condition of the macro in my code.  I have the two conditions  where I want to  output the error in log based on the input macro variable 'fld' . If it starts with numeric then it have to put one condition otherwise it need to put another error in log ( most of my names with 'SC' if its not numeric

In my example fld= 101-281 then I am expecting  to print 'ERROR: 101281 starts with Numeric", My second one is mostly my name starts with 'SC' how can I control the second condition using the ':' colon in the % if condition to print 'ERROR:&dsn ( numeric values of the 'fld' name)  starts with alpha character SC" 

I am able to use ':' in dataset condition but not sure how to use it the macro, instead of writing every  name in the 'If' Condtion.

Thank you for your inputs.

%macro check (fld=);
*%global output dsn;
%let output = %sysfunc(compress(&fld, "-"));


%if &output ^=: SC %then %do;
	%let dsn= %substr(&output.,1,6);

data _281;
	putlog  "ERROR: &dsn starts with Numeric";
run;

%end;

%else %if &output = :SC %then %do;
	%let dsn= %substr(&output.,3,6);
data _109;
	putlog  "ERROR:&dsn starts with alpha character SC";
run;
%end;

%put &output &dsn;


%mend;

%check (fld= 101-281);
%check (fld= 121-281);
%check (fld= SC100426);
%check (fld= SC100843);
%check (fld= SC102126);
%check (fld= SC105143);

0 Likes
2 REPLIES 2
SASKiwi
Opal | Level 21

You can't use '=:' in macro logic. It is simply not available. You can do the same thing though like this:

%if %substr(&output,1,2) ^= SC %then %do;
0 Likes
PeterClemmensen
Tourmaline | Level 20

Unfortunately, the colon operator is not in the list of macro operators. Would be cool though.

0 Likes
JUST RELEASED

SAS Viya with pay-as-you-go pricing.

Deploy software automatically at the click of a button on the Microsoft Azure Marketplace.

Learn more

55 percent discount.jpg

Recommended by SAS
These recommendations are generated using AI from SAS. For personalized recommendations, sign in with your SAS profile.
Discussion stats
  • 2 replies
  • 56 views
  • 0 likes
  • 3 in conversation