BookmarkSubscribeRSS Feed

Custom Task Tuesday: Combine Viya & V9 Data Summaries

Started ‎09-18-2018 by
Modified ‎03-21-2019 by
Views 1,568

This week's Custom Task combines the output from PROC MEANS (V9) and PROC CARDINALITY (Viya). The task willmedium.jpg

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:

 

task.PNG

Here are a few snapshots of what the resulting data set looks like:1.PNG 2.PNG

 

Full CodeTemplate (SAS Code) for This Task

All the task-user needs to supply is their CAS table and the task will do the rest! The following code will:

  • run PROC MEANS (with all of the measures that do not appear in PROC CARDINALITY)
  • run PROC CARDINALITY
  • combine the results into a table called SUMMARYSTATS, using a MERGE statement
  • rename several variables so that all of the output variables are Proper Case and do not contain underscores
  • print out the SUMMARYSTATS table
#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!

 

Join the Conversation on Twitter

Use the hashtag #CustomTaskTuesday and tweet Twitter_bird_logo_2012.svg.png@OliviaJWright with your Custom Task comments and questions!

 

Want to try it yourself?

Visit our SAS Studio GitHub to download the code for this task and follow along. 

 Take Me to GitHub!

Version history
Last update:
‎03-21-2019 11:41 AM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags