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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4 replies
  • 926 views
  • 0 likes
  • 2 in conversation