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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 858 views
  • 0 likes
  • 3 in conversation