BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sas_noob420
Calcite | Level 5

Hey guys,

 

 I am new to macros. I'm having trouble getting it to run properly. &q resolves into either a 0 or 1. Whenever is resolves to a one then d=1, I then want it to assign variable1 the variable Count_parameter so I can use it in the bottom macro. If &q resolves to 0 then I want there to be no variable name in the parameter so that it is missing. However whenever I run it regardless of the value of d the variable one is always missing and then the parameters are missing from the next macro. I know this is because of the way SAS compiles, but I don't know how to fix it. Thank you!

 

%Let C1=Count_Parameter

 

d=&q;

 

%IF d=1 %THEN %DO;
   %let variable1=&C1;
  %END;
  %Else %DO;
   %let variable1= ;
  %END;

 

%macroexample(var=variable1);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

The expression

 

   %if d=1 %then %do;

 

will NEVER be true.   Macro thinks you are comparing a one-letter character string (d) to the single digit (1).  You have to tell macro that D is a macro variable, not a literal text.  That's what the leading ampersand is for   So, lesson 1 in macro coding, try

 

   %if &d=1 %then %do;

 

But before you get there you also need to change

   d=&q;

 

to

  %let d=&q;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

2 REPLIES 2
mkeintz
PROC Star

The expression

 

   %if d=1 %then %do;

 

will NEVER be true.   Macro thinks you are comparing a one-letter character string (d) to the single digit (1).  You have to tell macro that D is a macro variable, not a literal text.  That's what the leading ampersand is for   So, lesson 1 in macro coding, try

 

   %if &d=1 %then %do;

 

But before you get there you also need to change

   d=&q;

 

to

  %let d=&q;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
sas_noob420
Calcite | Level 5

Hallelujah! Thank you! It worked. I tried everything for hours, but that. Smiley Happy

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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