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

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.

 

 

             

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.

View solution in original post

4 REPLIES 4
Reeza
Super User

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.

xiaoyao026
Calcite | Level 5

Hi Reeza

 

thank you for quick reply, i copy your code and try to run in project, unfortunately got error below:

 

 

Capture.PNG

 

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.

xiaoyao026
Calcite | Level 5

thank you to both of you.

 

after some trying, finally i got result i want (not easy to figure out though Smiley Frustrated)

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1169 views
  • 0 likes
  • 3 in conversation