Hi Everyone
Recently working on an EG project, and now facing below issue (sorry, i'm poor on SAS programing), would it be possible to help to provide your advice?
i use SAS programing to try to create a new table, base on 2 different original data tables. i want to have set up a Prompt to decide which original tables should be copied to new table. below is my code:
data WORK.QUERY_FOR_PRODUCTS2_0004;
%macro reports;
%if "&include" EQ "YES" %then
set WORK.query_for_products_0002
WORK.QUERY_FOR_PRODUCTS2_0004=WORK.QUERY_FOR_PRODUCTS_0002;
%else %if "&include" EQ "NO" %then
WORK.QUERY_FOR_PRODUCTS2_0004=WORK.QUERY_FOR_PRODUCTS_0001;
%mend reports;
run;
but it looks like not working properly. output is blank actually.
Thank you very much in advance.
I think you want something that's more like the following:
%macro reports(include);
data WORK.QUERY_FOR_PRODUCTS2_0004;
%if "&include" EQ "YES" %then %do;
set WORK.query_for_products_0002
WORK.QUERY_FOR_PRODUCTS2_0004 WORK.QUERY_FOR_PRODUCTS_0002;
%end;
%else %if "&include" EQ "NO" %then %do
SET WORK.QUERY_FOR_PRODUCTS2_0004 WORK.QUERY_FOR_PRODUCTS_0001;
%end;
run;
%mend reports;
%reports(YES);
I don't think your SET statements are quite correct though, not sure what you were expecting from the = sign.
My suggestion would be to get it working without a macro to see the correct code structure and then modify my macro above.
I think you want something that's more like the following:
%macro reports(include);
data WORK.QUERY_FOR_PRODUCTS2_0004;
%if "&include" EQ "YES" %then %do;
set WORK.query_for_products_0002
WORK.QUERY_FOR_PRODUCTS2_0004 WORK.QUERY_FOR_PRODUCTS_0002;
%end;
%else %if "&include" EQ "NO" %then %do
SET WORK.QUERY_FOR_PRODUCTS2_0004 WORK.QUERY_FOR_PRODUCTS_0001;
%end;
run;
%mend reports;
%reports(YES);
I don't think your SET statements are quite correct though, not sure what you were expecting from the = sign.
My suggestion would be to get it working without a macro to see the correct code structure and then modify my macro above.
Hi Reeza
thank you for quick reply, i copy your code and try to run in project, unfortunately got error below:
the purpose i want to achieve via "=" is for example, when i choose "include" = YES, i want WORK.QUERY_FOR PRODUCTS2_0004 has same data as WORK.QUERY_FOR_PRODUCTS_0002.
Thank you in advance.
A semicolon is missing after the second %then %do in @Reeza's code.
thank you to both of you.
after some trying, finally i got result i want (not easy to figure out though )
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.