Sas declare variable as array

I have a dataset with columns - User_id Condition1 Condition 9 Condition 11. Condition 102

I want to perform array functions, is there any way to declare conditions as an array? The problem is the numbers aren't uniform, ie, it isn't Condition1, Condition2, Condition3 and so on.

I was thinking something like:

array conds condition: ;

But it didn't work.

1 ACCEPTED SOLUTION
Accepted Solutions Rhodochrosite | Level 12 Re: SAS declare existing variables as array Posted 03-03-2021 02:18 PM (701 views) | In reply to rdum96

You can use the form

The colon after cond covers all variables beginning with cond. They must be same type, numeric or character. If they are char the $ sign is needed.

3 REPLIES 3 Rhodochrosite | Level 12 Re: SAS declare existing variables as array Posted 03-03-2021 02:18 PM (702 views) | In reply to rdum96

You can use the form

The colon after cond covers all variables beginning with cond. They must be same type, numeric or character. If they are char the $ sign is needed.

Calcite | Level 5 Re: SAS declare existing variables as array Posted 03-03-2021 02:33 PM (688 views) | In reply to ErikLund_Jensen That worked! Thank you! Super User Re: SAS declare existing variables as array Posted 03-03-2021 04:47 PM (661 views) | In reply to ErikLund_Jensen

If the variables already exist the $ in the array is not needed:

data _null_; set sashelp.class (obs=1); array c name sex; do i=1 to dim(c); put "Value is: " c[i]; end; run;
121 data _null_; 122 set sashelp.class (obs=1); 123 array c name sex; 124 do i=1 to dim(c); 125 put "Value is: " c[i]; 126 end; 127 run; Value is: Alfred Value is: M NOTE: There were 1 observations read from the data set SASHELP.CLASS. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds

No warnings or anything, output as expected.

I would not say "do not add the $", just saying not required.