This week's Custom Task combines the output from PROC MEANS (V9) and PROC CARDINALITY (Viya). The task will
output CAS tables from both PROCs and then merge them into one summary CAS-table. For measures that are available in both PROC MEANS and PROC CARDINALITY, the PROC CARDINALITY measure was used (but they will be the same 🙂 ).
PROC MEANS is a V9 procedure that has been CAS-Enabled. This means that using PROC MEANS will run CAS actions behind-the-scenes, and will be more efficient than using a different V9 PROC, like PROC UNIVARIATE.
Here's what the task looks like:
Here are a few snapshots of what the resulting data set looks like:
All the task-user needs to supply is their CAS table and the task will do the rest! The following code will:
#set($inputLibrefIndex = $DATASOURCE.toString().indexOf("."))
#set($inputCASLibref = $DATASOURCE.toString().substring(0, $inputLibrefIndex))
%let inputLibref = $inputCASLibref;
ods exclude all;
proc means data=$DATASOURCE css cv clm lclm uclm mode median p1 p5 p10 p25 p75 p90 p95 p99 qrange probt t range stderr sum uss var
STACKODSOUTPUT;
ods output Summary=&inputLibref..MEANS;
run;
ods exclude none;
proc cardinality data=$DATASOURCE outcard=&inputLibref..card;
run;
data &inputLibref..SummaryStats;
length variable $50.;
merge &inputLibref..means &inputLibref..card(rename=(_VARNAME_=Variable));
by variable;
rename _FMTWIDTH_ = FormatWidth
_TYPE_ = Type
_RLEVEL_ = RLevel
_ORDER_ = Order
_MORE_ = More
_CARDINALITY_ = Cardinality
_NOBS_ = NObs
_SUMFREQS_ = SumFreqs
_NMISS_ = NMiss
_MISSFMT_ = MissFormat
_VISIBLE_ = Visible
_MIN_ = Min
_MAX_ = Max
_MEAN_ = Mean
_STDDEV_ = StdDev
_SKEWNESS_ = Skewness
_KURTOSIS_ = Kurtosis
_MFREQ_ = MFreq
_MFREQFOUNDLEVEL_ = MFreqFoundLevel
_MFREQNUM_ = MFreqNum
_MFREQCHR_ = MFreqChr
_MFREQCFMT_ = MFreqCFormat
_LASTNUM_ = LastNum
_LASTCHR_ = LastChr
_LASTCFMT_ = LastcFormat;
run;
title "&inputLibref..SUMMARYSTATS";
proc print data=&inputLibref..summarystats;
run;
How would you improve this task? Do you have other ideas for combining Viya and V9 code into one Custom Task? Comment on this article and let me know!
Use the hashtag #CustomTaskTuesday and tweet @OliviaJWright with your Custom Task comments and questions!
Visit our SAS Studio GitHub to download the code for this task and follow along.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.