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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 217 views
  • 0 likes
  • 2 in conversation