/*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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: