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 )
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.