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

Hello all,

Please have a look on this-

I have written one sql code and applied macros on it-

The Macro looks like-

%Macro  Result (Cod, Report);

proc sql;

connect to oracle (user=xxxx password=xxxx path='xxx');

create table One as select * from connection to oracle

( select    p1, p2, p3, Code

from Two

where code= &Cod;

disconnect from oracle;

quit;

data &report;

set one;

.

.

.

.

run;

%Mend;

% Result (Code =      ,    Report = Rpt1_overall);

% Result (Code =  23 , Report = Rpt2);

% Result (Code =  43, Report = Rpt3);

% Result (Code =  32, Report = Rpt4);

Here, I don't have problem with last three macros but for the fist macro I don't want to define any code (value). in the proc sql step, I just want to select code, no 'where' condition.
So how can I do so?
Hope you understand this query.

Regards

Dipu

1 ACCEPTED SOLUTION

Accepted Solutions
Amir
PROC Star

Hi,

Perhaps try substituting the whole where clause, so instead of:

where code= &Cod

you could use:

&Cod

Then you could invoke the macro as follows:

% Result (,    Report = Rpt1_overall);

% Result (where Code =  23 , Report = Rpt2);

% Result (where Code =  43, Report = Rpt3);

% Result (where Code =  32, Report = Rpt4);

Regards,

Amir.

View solution in original post

4 REPLIES 4
Amir
PROC Star

Hi,

Perhaps try substituting the whole where clause, so instead of:

where code= &Cod

you could use:

&Cod

Then you could invoke the macro as follows:

% Result (,    Report = Rpt1_overall);

% Result (where Code =  23 , Report = Rpt2);

% Result (where Code =  43, Report = Rpt3);

% Result (where Code =  32, Report = Rpt4);

Regards,

Amir.

Dipu
Calcite | Level 5

Thank you Amir for your reply.

Actually it worked, I was just worried since I had various 'and' conditions so I did the same as you mentioned, for 'and'.

Thank you

Dipu

Astounding
PROC Star

Here's another possibility you could try.  You currently have:

from Two

where cod=&cod

;

Try replacing that with:

from Two

%if %length(&cod) %then where cod=&cod;

;

Yes, you do need both semicolons.  Good luck.

Dipu
Calcite | Level 5

Thank you @ Astounding for your reply.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 4 replies
  • 1225 views
  • 5 likes
  • 3 in conversation