BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
%macro Generate_transformed_Scored
(variable=,
Has_Left=0,
Has_Right=0,
Left_value=0,
Right_Value=0,
Meaningful_Null=1,
condition1=LE-100000000,
condition2=LE-100000000,
condition3=LE-100000000,
condition4=LE-100000000,
condition5=LE-100000000,
condition6=LE-100000000,
condition7=LE-100000000,
condition8=LE-100000000,
condition9=LE-100000000);

then later I have the following:
%Generate_transformed_Scores (variables=LongestOverdueMonth,Has_Left=0,Has_Right=0,
condition1=>=3,
condition1=>=2,
condition1=>=1,
condition1=<1,
Meaningful_Null=0);

are the cobdition actually boolean? what does =>= means?

what is the macro trying to achieve?

8 REPLIES 8
SASKiwi
PROC Star

what does =>= means?

This is a macro parameter: condition1=>=3,

 

It is the same as doing this:

%let condition1 = >=3;
%put condition1 = &condition1;

It is assigning the text ">=3" (greater than or equal to 3) to a macro variable condition1.

 

You haven't provided the source code within the macro so I have no idea what it is doing.

ballardw
Super User

Without all of the code between %macro to %mend; there is no way to determine what any macro does.

 

I could write a macro that has 5 parameters and doesn't actually use any of them for anything example:

%macro dummy(var1=, var2=, var3=, var4= , var5=);
Proc print data=sashelp.class;
run;
%mend;

Does not matter what the value of any of the parameters might be, all this macro will ever do is print the Sashelp.class dataset OR generate errors about a missing data set if someone has removed the dataset class from the sashelp library.

 

 

Tom
Super User Tom
Super User

The CALL to the macro is pretty clear (other than having the commas on the wrong ends of the lines where they are harder for humans to see and create).

 

Let's just insert some leading spaces into the values (which the macro processor will ignore) to make it clearer what part is the parameter name and what part is the value being assigned to the parameter.

%Generate_transformed_Scores
(variables=       LongestOverdueMonth
,Has_Left=        0
,Has_Right=       0
,condition1=      >=3
,condition1=      >=2
,condition1=      >=1
,condition1=      <1
,Meaningful_Null= 0
);

What I want to know is why is the default conditions to test if the value is less than or equal to negative 100 million?

HeatherNewton
Quartz | Level 8

I still dont understand what it means by

 

condition1=      >=3

 

let me check why but I am not sure if it was explain anywhere...

Kurt_Bremser
Super User

@HeatherNewton wrote:

I still dont understand what it means by

 

condition1=      >=3

 

let me check why but I am not sure if it was explain anywhere...


The macro parameter condition1 is set to the text(!)

>=3

and wherever the macro parameter is used in the macro, it is replaced by this text before the created code is sent to the SAS interpreter.

Tom
Super User Tom
Super User

@HeatherNewton wrote:

I still dont understand what it means by

 

condition1=      >=3

 

let me check why but I am not sure if it was explain anywhere...


Is is the same as setting condition1 to ABC or 1234.

 

I suspect since the variable is named CONDITION and the contents includes an operator >= and a number that most likely the macro variable is going to be used to generate a boolean expression.

Something like:

if myvar &condition1 then put "Condition One was met";

Which would be converted by the macro processor into this statement.

if myvar >=3 then put "Condition One was met";
HeatherNewton
Quartz | Level 8
%macro Generate_transformed_Scored
(variable=,
Has_Left=0,
Has_Right=0,
Left_value=0,
Right_Value=0,
Meaningful_Null=1,
condition1=LE-100000000,
condition2=LE-100000000,
condition3=LE-100000000,
condition4=LE-100000000,
condition5=LE-100000000,
condition6=LE-100000000,
condition7=LE-100000000,
condition8=LE-100000000,
condition9=LE-100000000);

&let variable1="&variable";
data transformation;
set &transform_para;
If var=&variable1;
format Null_score Slope Intercept b_score c_score d_score e_score f_Score g_score h_score i_score d19.14;
run;

Proc sql;
select Null_score into: Null_Score from transformation;
select Slope into: Slope from transformation;
select b_Score into: b_score from transformation;
select c_Score into: c_score from transformation;
select d_Score into: d_score from transformation;
select e_Score into: e_score from transformation;
select f_Score into: f_score from transformation;
select g_Score into: g_score from transformation;
select h_Score into: h_score from transformation;
select i_Score into: i_score from transformation;
quit;

data transformed_score_temp (keep=&variable score &matchby);
set &relevant_tab;
format Null_score Slope Intercept b_score c_score d_score e_score f_score g_Score h_Score i_Score d19.4;

score=&variable*&slope +&intercept;

if &Has_LEft=1 then do;
if &variable<&Left_Value then score=&Left_Value*&slope +&intercept;
end;

if &Has_Right=1 then do;
if &Variable > &Right_Value then score=&Right_Value*&slope+&intercept;
end;

if &variable &condition9. then score=&i_score;
if &variable &conditioon8. then score=&h_score;
if &variable &conditioon7. then score=&g_score;
if &variable &conditioon6. then score=&f_score;
if &variable &conditioon5. then score=&e_score;
if &variable &conditioon4. then score=&d_score;
if &variable &conditioon3. then score=&c_score;
if &variable &conditioon2. then score=&b_score;
if &variable &conditioon1. then score=&Null_score;
if &variable =. and &Meaningful_Null=1 then score=&Null_score;
if &variable =. and &Meaningful_Null=0 then score=.;
run;

then later we see the followings:
then later I have the following:
%Generate_transformed_Scores (variables=LongestOverdueMonth,Has_Left=0,Has_Right=0,
condition1=>=3,
condition1=>=2,
condition1=>=1,
condition1=<1,
Meaningful_Null=0);

I added more code for reference. Please kindly review and enlighten me. Thanks.

ballardw
Super User

Won't say anything about what that code is supposed to do because you still have not included ALL the code between %Macro and %mend. All of it.

 

So far basically what I see is 1) a reference to data sets with a macro variable without definition anywhere:

set &transform_para;
set &relevant_tab;

That macro variable is not a parameter and not defined. So without a definition for these variables all this code will do is generate errors about no data set on a SET statement and then perhaps run or not if there is currently a data set named Transformation in the Work library (that may well not have any of the correct variables or expected values).

 

Don't see definitions for

&matchby

&intercept

either.

 

Another reason for suspecting not very familiar with the macro language is reading the same data set 10 times to populate 10 macro variables which can be done with a single pass:

proc sql noprint;
   select sex,age into :SS separated by '/', :AA separated by ','
   from sashelp.class
   ;
quit;
%put SS is: &ss. , AA is: &aa.;

 

 

This bit code tells me that that it is highly likely that only one of the macro conditions really should be set:

 

if &variable &condition9. then score=&i_score;
if &variable &conditioon8. then score=&h_score;
if &variable &conditioon7. then score=&g_score;
if &variable &conditioon6. then score=&f_score;
if &variable &conditioon5. then score=&e_score;
if &variable &conditioon4. then score=&d_score;
if &variable &conditioon3. then score=&c_score;
if &variable &conditioon2. then score=&b_score;
if &variable &conditioon1. then score=&Null_score;

Reason: Since there are multiple conditions that all assign values to the exact same variable then only the lowest numbered condition is actually kept in the result. So why bother setting more than 1???? Additionally NONE of those "conditioon" macro variables exist because the parameters defined are spelled with one o as in "condition" not "conditioon".

 

Except for &Condition9 which is spelled correctly those statements resolve to something like

if "variable" then score= <the assignment for that line>.

If the value passed into the macro for variable does not resolve to something that can be made numeric that will create an error for "Invalid numeric data

 

And lastly your shown example of the macro call:

%Generate_transformed_Scores (variables=LongestOverdueMonth,Has_Left=0,Has_Right=0,
condition1=>=3,
condition1=>=2,
condition1=>=1,
condition1=<1,
Meaningful_Null=0);

Will throw an error first because the macro defined name shown is GENERATE_TRANSFORMED_SCORED, not GENERATE_TRANSFORMED_SCORES If you get that fixed you have another set of errors because the parameter VARIABLES is not defined for the Macro, the variable name is VARIABLE.

And has multiple Condition1, so will throw a completely different set of errors

ERROR: The keyword parameter CONDITION1 passed to macro GENERATE_TRANSFORMED_SCORED was given a value twice.

Some one needs to check spelling frequently.

 

Most of the time when some one builds as many macro variables that code appears to do then there is a poor understanding of what the macro language should be used for (I know, I've been there). Pulling values out of data set, sticking them into macro variables just so they can be used in a formula means that someone didn't know how to combine data sets so the actual variables from the original data set could be used.

 

 

Without examples of the INPUT data sets complete and correct code can't say what it is supposed to do. What is shown is going to throw a number of errors.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 8 replies
  • 1061 views
  • 0 likes
  • 5 in conversation