it can take parameters to accept the low-range and high-range and see if the value is within the range then display the exact range but if the value is less than or greater than the range then display '$$$'.
how do i make this code generic... can u please suggest a solution.
%macro check (dsn=, dsn2=);
data &dsn;
set &indsn (Keep=Age);
run;
proc format;
value band 10 - <12 = '11 - 12'
other = '$$$';
run;
proc print data= &dsn;
format age band.;
run;
%mend check;
%check (dsn=, dsn2=);
If you are taking parameters for the macro then why didn't you show them in your macro.
Also the way you have constructed this format, even as an example
proc format;
value Numericband
10 - <12 = '11 - 12'
15 - <25 = '16 - 21' (why do you confuse 25 and 21 here by the way)
other = '***';
run;
actually has 2 ranges. So if you give a single High and single low value how do you construct 2 ranges?
This is an example of creating a single range with a format
%macro numeric_band_check (indsn=, dsn=, low=, high=);
data &dsn;
set &indsn (Keep=Age);
run;
proc format;
value Numericband
&low - < &high = "&low - &high"
other = '***';
run;
proc print data= &dsn;
format age Numericband.;
run;
%mend numeric_band_check;
%numeric_band_check (indsn=sashelp.class, dsn=test);
Why do you think that you need a macro?
This is a perfect use case for a user defined format (see PROC FORMAT in the doc).
i have huge data so need a generic macro to code so asking help to code it in a macro.
That statement makes no sense to me, why would a macro be more efficient than a format?
Perhaps you need to describe your constraints and requirements in more detail.
As @LinusH has said, there is no need for macro, macro language is for generating Base SAS code - it is not code in itself. There is nothing at all in your post to indicate the need for generated code, it is a very basic logic gate scenario:
result=ifc(12 <= age <= 15,"12-15","$$$");
Alternatively you can use formats as suggested, however personally with the whole 32/64 debacle I avoid any form of proprietary compiled file where at all possible.
Another alternative is to have a dataset containing your values and merge that on, if there are a lot of them.
Simple as any other merge, example:
data ranges; low=12; high=15; result="12-15"; run; data have; age=10; output; age=14; output; run; proc sql; create table WANT as select A.*, COALESCE(B.RESULT,"$$$") as RESULT from HAVE A left join RANGES B on B.LOW <= A.AGE <= B.HIGH; quit;
Proc format;
valie age_fmt
12 -15 = '12-15'
other = $$$';
run;
age15 = put(age, age_fmt.);
@Reeza above i have posted my code but i want to make this code a generic code so that it can take parameters to accept the low range and high range and see if the value is within the range then display the exact range but if the value is less than or greater than the range then display '$$$'. how do i make this code generic... can u please suggest a solution.
If you are taking parameters for the macro then why didn't you show them in your macro.
Also the way you have constructed this format, even as an example
proc format;
value Numericband
10 - <12 = '11 - 12'
15 - <25 = '16 - 21' (why do you confuse 25 and 21 here by the way)
other = '***';
run;
actually has 2 ranges. So if you give a single High and single low value how do you construct 2 ranges?
This is an example of creating a single range with a format
%macro numeric_band_check (indsn=, dsn=, low=, high=);
data &dsn;
set &indsn (Keep=Age);
run;
proc format;
value Numericband
&low - < &high = "&low - &high"
other = '***';
run;
proc print data= &dsn;
format age Numericband.;
run;
%mend numeric_band_check;
%numeric_band_check (indsn=sashelp.class, dsn=test);
@RTelang playing 20 questions isn't efficient.
How do you plan to pass/generate these boundaries? Is this an attempt at creating indicator variables?
@RTelang wrote:
@ballard thanks for the input but there another parameter variable= which is to be incorporated in the macro age shouldn't be hard coded how do it.
It looks like time to read up the documtentation on parameters. If you have a parameter for your input data set, output and see how to use that then why is it difficult to pick your paramenter name and use it where AGE is currently in the code?
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!
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.