I need shortest way for creating Var0-Var10 with 0 value.
Sample:
VAR0 VAR1 VAR2 ...
0 0 0
data want; array var{10} 8 (0,0,0,0,0,0,0,0,0,0); run;
That would create var1-var10. There doesn't seem to be a simple method of it:
data want; retain var0 var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 0; run;
data want; array x var0-var10; do over x; x=0; end; run;
I mean you could do:
options missing=0; data want; length var0-var10 8; run;
But that is not actually setting the value, just changing the system default.
I suppose the real question is why you would need to, are you performing some calculation and want a template to add to or sum with? There is likely to be better methods, but need more information.
if you have dataset then probably do.
data want;
set have;
array h(*) var0-var10;
do i = 1 to dim(h);
if h(i)= . then
h(i) = 0;
end;
run;
If your counting something then you shouldn't need to create variables? If the data doesn't have something that you are expecting, either add a template, or pad out the data you already have.
one way
data want;
retain var1-var10 0;
run;
Is your question just to create an(one) observation?
or is there a bigger objective?
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.