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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1193 views
  • 3 likes
  • 3 in conversation