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?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.