Here is the SAS code to get the unique values of all character variables in a dataset:

/* Create a sample dataset */ data sample; input name $ gender $ age; datalines; John M 25 Mary F 30 David M 40 Susan F 35 ;

/* Get the list of character variables */ proc contents data=sample out=contents; run;

data null; set contents; if type='char' then call symput('char_vars',trim(name)||' '); run;

/* Get the unique values of all character variables */ %macro unique_values(); %do i=1 %to %sysfunc(countw(&char_vars)); %let var=%scan(&char_vars,&i); proc sql; select distinct &var into :&var separated by ',' from sample; quit; %put Unique values of &var: &&&var; %end; %mend;

%unique_values()

SAS code for getting the unique value of all character variables in one dataset

原文地址: https://www.cveoy.top/t/topic/grfk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录