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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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