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);
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;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;Unfortunately, the colon operator is not in the list of macro operators. Would be cool though.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.
