BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Vahe_Mar
Obsidian | Level 7

I need shortest way for creating Var0-Var10 with 0 value.

Sample:

VAR0 VAR1 VAR2 ...

  0         0         0

 

 

 

Thanks,
Vahe
1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12

one way

 

data want;
retain var1-var10 0;
run;

View solution in original post

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26
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.

Vahe_Mar
Obsidian | Level 7
RW9 Thanks for answering. Yes i am calculating something and final data should have 10 variables. Some of calculation have two some of 3 , i need set it together and if have missing values in calculation I will have 0 instead of missing.
Thanks,
Vahe
kiranv_
Rhodochrosite | Level 12

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;
Vahe_Mar
Obsidian | Level 7
Thanks used this way
Thanks,
Vahe
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

kiranv_
Rhodochrosite | Level 12

one way

 

data want;
retain var1-var10 0;
run;
novinosrin
Tourmaline | Level 20

Is your question just to create an(one) observation?

 

or is there a bigger objective?

Vahe_Mar
Obsidian | Level 7
Dear novinosrin ,
just create one obs its part of coding with other part I am good thanks for asking
Thanks,
Vahe

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2656 views
  • 3 likes
  • 4 in conversation