BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

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);

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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;

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

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;
PeterClemmensen
Tourmaline | Level 20

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 691 views
  • 3 likes
  • 3 in conversation