BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
各位专家您好,我有一个技术问题亟待解决,如果可以通过 fcmp 函数中的“run_macro”语句调用宏语句,并且在数据程序步骤中调用 PROC 过程步骤,但是 fcmp 函数在 proc ds2 中无法使用,则会提示无法识别“run_macro”的错误消息, 如何解决这个问题?
/*Runs successfully*/
%macro distinct_values;

%let input_table = %sysfunc(dequote(&input_table));

%let column = %sysfunc(dequote(&column));

%let output_table = %sysfunc(dequote(&output_table));

proc sql;

create table &output_table as

select distinct &column

from &input_table;

%mend;

proc fcmp outlib=work.funcs.sql;

function get_distinct_values(input_table $, column $, output_table $);

rc = run_macro('distinct_values', input_table, column, output_table);

return (rc);

endsub;
run;
data _null_;

rc = get_distinct_values('sashelp.shoes', 'region', 'work.regions');

id=open('work.regions');

if id then nobs=attrn(id,'NOBS');

put nobs;

run;

/*If you use proc DS2 instead of the data step, the run fails*/
PROC DS2 ;
PACKAGE FUNCTION_PACK / OVERWRITE=YES LANGUAGE='FCMP' TABLE='WORK.FUNCS';
ENDPACKAGE;
RUN;
QUIT;
PROC DS2;
DCL PACKAGE FUNCTION_PACK P();
MENTHOD RUN();
rc = get_distinct_values('sashelp.shoes', 'region', 'work.regions');

id=open('work.regions');

if id then nobs=attrn(id,'NOBS');

put nobs;

run;
END;
ENDDATA;
RUN;
QUIT;
1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
_Sas_Beginner_
Quartz | Level 8
Hello experts, I have a technical problem that needs to be solved urgently, if you can call the macro statement through the "run_macro" statement in the fcmp function, and call the PROC procedure step in the data program step, but the fcmp function cannot be used in proc ds2, it will prompt the error message that "run_macro" is not recognized, how to solve this problem?
yabwon
Onyx | Level 15

Some interesting facts described by @RichardDeVen can be read in this thread:

https://communities.sas.com/t5/SAS-Programming/Output-to-a-Macro-variable-within-DS2/td-p/692726

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



_Sas_Beginner_
Quartz | Level 8
thanks!but I tried the code you sent me to my website with the error message "Cannot find function" run_macro"";
_Sas_Beginner_
Quartz | Level 8
I mean, run the macro with the fcmp function and then call the fcmp function with proc ds2, but always prompt an error message!
_Sas_Beginner_
Quartz | Level 8
sorry,I didn't pay attention to the content of the answer,thank you very much!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 692 views
  • 1 like
  • 2 in conversation