/*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;
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
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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.