Create a SAS Array with non-consecutive variable names

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Create a SAS Array with non-consecutive variable names

I have this syntax to achieve this result:

 

data have;
     set want;
          array xs(*) var1-var5 
           all = max(of xs(*));
run:

var1      var2     var3     var4     var5     all  

     1           .            .           .          .        1

     .           3            .           .          .        3

     .           .            2           .          .        2

     .           .            .           6          .        6

     .           .            .           .          8        8

 

If I have data like this, where var3 is missing, will the same syntax work for this?

 

var1      var2      var4     var5     all  

     1           .            .          .         1

     .           3            .           .        3

     .           .            2           .        2

     .           6           .            .        6

     .           .            .            8       8


Accepted Solutions
Solution
‎12-17-2017 12:10 PM
Super User
Posts: 10,689

Re: Create a SAS Array with non-consecutive variable names

Posted in reply to MB_Analyst
data have;
     set want;
           all = max(of var: );
run:

View solution in original post


All Replies
Solution
‎12-17-2017 12:10 PM
Super User
Posts: 10,689

Re: Create a SAS Array with non-consecutive variable names

Posted in reply to MB_Analyst
data have;
     set want;
           all = max(of var: );
run:
PROC Star
Posts: 8,147

Re: Create a SAS Array with non-consecutive variable names

[ Edited ]
Posted in reply to MB_Analyst

Or, if your variables names don't start with "var", you could use a variable list that only relies on the variable order in the dataset. i.e.:

data want;
     set have;
          array xs(*) var1--var5;
           all = max(of xs(*));
run;

Art, CEO, AnalystFinder.com

 

Super User
Super User
Posts: 7,932

Re: Create a SAS Array with non-consecutive variable names

Posted in reply to MB_Analyst

Yes.

But SAS will create an empty (all missing) variable named VAR3.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 91 views
  • 0 likes
  • 4 in conversation