BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

Here is the code I'm trying to execute but keep hitting error.

&FLG is a variable imported from a different table

&macro1 and &macro2 are variables I'm trying to store values based on the condition rules (condition1-4).

 

<The original code with success>

data want;

  set table;

    where condition;

       if condition1 then do;

             &macro1.

      end;

      else do;

            &macro2.

      end;

run;

 

 

<The edited code with failure>

data want;

  set table;

    where condition;

    if &FLG. eq Y then do;

       if condition1 then &macro1.;

       if condition2 then &macro2.;

    end;

    if &FLG. eq N then do;

       if condition3 then &macro1.;

       if condition4 then &macro2.;

    end;

run;

 

It would be a great help if you can advise which part I'm missing and how to fix the code to run successfully.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

In data step code, you compare variables or values. Character values have to be enclosed in quotes. So, when your %flg macro returns either a Y or N, the data step code has to be

 if "%FLG" eq "Y" then do;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

In data step code, you compare variables or values. Character values have to be enclosed in quotes. So, when your %flg macro returns either a Y or N, the data step code has to be

 if "%FLG" eq "Y" then do;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 308 views
  • 0 likes
  • 2 in conversation