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

Hi,

 

I am writing an array for splitting the data set based on their values of several variables, like I have a data set which has 20 variables and their values are 0 and 1 and now I want to split the data set in two, one data set which has at least one or more value of 1 in any of the 20 variables for example

IDD_1D_2D_3D_4D_5D_6D_7D_8D_9D_10D_11D_12D_13D_14D_15D_16D_17D_18D_19D_20
80746901000000000000000001

 

and second one which has value having 0 across all 20 variables for example

 

IDD_1D_2D_3D_4D_5D_6D_7D_8D_9D_10D_11D_12D_13D_14D_15D_16D_17D_18D_19D_20
80756900000000000000000000

 

I am trying this method but it not giving the desired result.

Data data1 rest; 
set data; 
array D {*} D_1-D_20; 
do I = 1 to 20; 
if D(I) > 0 then output data1; 
else output rest; 
end; 
run;
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Or

 

Data data1 rest; 
    set data; 
    array D {*} D_1-D_20; 
    if 1 in D then output data1;
    else output rest;
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

You can do something like below. I simply made up some data

 

data data;
    array D {*} D_1-D_20;
    do i=1 to 20;
        D[i]=0;
    end;
    output;
    D[1]=1;
    output;
run;

Data data1 rest; 
    set data; 
    array D {*} D_1-D_20; 
    if sum(of D[*]) > 0 then output data1;
    else output rest;
run;
umeshgiri48
Obsidian | Level 7
This solution is also working. Thanks
PeterClemmensen
Tourmaline | Level 20

Or

 

Data data1 rest; 
    set data; 
    array D {*} D_1-D_20; 
    if 1 in D then output data1;
    else output rest;
run;
umeshgiri48
Obsidian | Level 7
Your both solutions are working, Thanks

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
  • 4 replies
  • 874 views
  • 0 likes
  • 2 in conversation