hi,
If i given a Categories =18; That is hard coded value for variable..... If i have a 18 variables (Category_1, Category_2, Category_3,Category_4,.....Category_18. how can i get a dynamic value for 'Categories' variable ?
thx,
There are probably a numbers of ways to do what I think you want to do. e.g.:
data have;
input Categories Category_1-Category_18;
cards;
18 1 2 3 0 0 1 2 3 0 0 1 2 3 0 0 1 2 3
18 2 3 4 0 7 2 3 4 0 7 2 3 4 0 7 2 3 4
;
run;
data want;
array cat Category_1-Category_18;
set have;
Categories=0;
do over cat;
Categories=sum(categories,cat ne 0);
end;
run;
is this what you want:
data have;
input Category_1-Category_18;
cards;
1 2 3 0 0 1 2 3 0 0 1 2 3 0 0 1 2 3
2 3 4 0 7 2 3 4 0 7 2 3 4 0 . . . .
;
run;
data want;
array cat Category_:;
set have;
do over cat;
Categories=sum(categories,cat ne .);
end;
run;
proc print;run;
C C C C C C C C C
C C C C C C C C C a a a a a a a a a C
a a a a a a a a a t t t t t t t t t a
t t t t t t t t t e e e e e e e e e t
e e e e e e e e e g g g g g g g g g e
g g g g g g g g g o o o o o o o o o g
o o o o o o o o o r r r r r r r r r o
r r r r r r r r r y y y y y y y y y r
O y y y y y y y y y _ _ _ _ _ _ _ _ _ i
b _ _ _ _ _ _ _ _ _ 1 1 1 1 1 1 1 1 1 e
s 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 s
1 1 2 3 0 0 1 2 3 0 0 1 2 3 0 0 1 2 3 18
2 2 3 4 0 7 2 3 4 0 7 2 3 4 0 . . . . 14
Or, if you have to check for both missing and zero:
data have;
input Categories Category_1-Category_18;
cards;
18 1 2 3 . 0 1 2 3 0 . 1 2 3 0 0 1 2 3
18 2 3 4 0 7 2 3 4 0 7 2 3 . 0 7 2 3 4
;
run;
data want;
array cat Category_1-Category_18;
set have;
Categories=0;
do over cat;
Categories=sum(categories,not(missing(cat)) and cat ne 0);
end;
run;
No! If you don't mind can i have any contact id (skype) so that i can share my screen and show the code where am struck up....Please need your help very badly
Perhaps a transpose followed by a select count(*) group by category work for you...?
Otherwise, it seems we're lacking information on how you would like to do the count...:smileyconfused:
You can attach your screen shot and code in a post on this forum
@ Arthur Sorry I can send an a email or i can show u by Skype, team viewer, join me.
you can reach me @ 4784gsks@gmail.com
Thanks,
: Since the benefit of sites like the forum is helping SAS users, as a group, to better learn and make better and more efficient use of the language, I have always refrained from one-on-one discussions. If you post your material on the forum, and can describe the problem in sufficient detail, that will be the best chance that you will receive the best answers.
If I understand your question then you're after nothing else than a way to count the number of elements in an array. If so then the dim() function will do.
data have;
array vars {18} 8.;
nArrayElements=dim(vars);
put nArrayElements=;
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 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.