Welcome to the Simplilearn Community

Want to join the rest of our members? Sign up right away!

Sign Up

DS with SAS | Mar 10 - Apr 8 | Ashutosh

Priyanka_Mehta

Well-Known Member
Simplilearn Support
Hello All,

Greetings from Simplilearn!!

Let us have a discussion about the course, explore the course here and try to resolve all our queries related to the same.

Happy Learning!!
 

_23837

Member
Alumni
Hi all,
I ran the following code and even though it is running fine, the if conditions in the macro ';assignment'; are not working as expected. Even though Field is resolving to the value 'profit' and yet it is calling the ';invalid'; macro instead of the 'valid' macro. What am i missing here? Any help in resolving this will be appreciated. :)

%let field = Profit;
%let utitle= "A report sorted by ";


option symbolgen;

%macro assignment (field, utitle);
%if &field="Sales" %then %valid(&field, &utitle);
%else %if &field='Profit' %then %valid(&field, &utitle);
%else %if &field="Discount" %then %valid(&field, &utitle);
%else %invalid;
%mend assignment;

%macro valid (field, utitle);
Proc sort data = "Electronic";
by &field;
title "&utitle - &field";
run;
%mend valid;

%macro invalid;
Proc Print ;
Title "Invalid field for sorting";
run;
%mend invalid;


%assignment(&field, &utitle);
 

K Manoj

Moderator
Staff member
Simplilearn Support
Try this:

Code:
%macro assignment (field, utitle);
%if  &field = Sales  %then  %valid(&field, &utitle);
%else %if  &field = Profit %then %valid(&field, &utitle);
%else %if  &field = Discount %then %valid(&field, &utitle);
%else %invalid;
%mend assignment;


The macro field is having the name of the variable which need not be put in quotes. Same to be done in the if else statement of assignment macro.
 

_23837

Member
Alumni
Try this:

Code:
%macro assignment (field, utitle);
%if  &field = Sales  %then  %valid(&field, &utitle);
%else %if  &field = Profit %then %valid(&field, &utitle);
%else %if  &field = Discount %then %valid(&field, &utitle);
%else %invalid;
%mend assignment;


The macro field is having the name of the variable which need not be put in quotes. Same to be done in the if else statement of assignment macro.




Yes it worked! Thank you! :)
 
Top