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

Hi,

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.

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @rdum96 

You can use the form

array c $ cond:;

 

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.

 

View solution in original post

3 REPLIES 3
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @rdum96 

You can use the form

array c $ cond:;

 

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.

 

rdum96
Calcite | Level 5
That worked! Thank you!
ballardw
Super User

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;

Log shows:

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.

 

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 811 views
  • 0 likes
  • 3 in conversation