Hi there,
I have 12 numeric variables (values of either 0,1,2) an am hoping to create a single variable which counts the number of "1"s or "2"s across rows (I have over 20 000 obs); e.g. how many 2s or 1s are in each row/record (rows can have both 1 or 2 - so wont be able to divide out) - I know there must be a simple way of doing this but haven't had much luck yet - any help would be greatly appreciated? Thanks so much!
Have you tried an array and do loop or are you looking for something different?
array vars(12) var1-var12;
var_count=0;
do i=1 to dim(vars);
if vars(i) in (1,2) then var_count+1;
end;
Peek?
Another one ,
data countc;
set have;
array v v1-v12;
ctof12=countc(cats(of v(*)),'12');
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.