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

Hi I was hoping someone can help me,

I have 1 table with multiple columns, one of the columns is called read_type which is either a 1,2,3 or a 4.

I would like to put all the 1 and 2 in one table and the 3 and 4 in another table. What is the best way to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data Table_A Table_B;
   set have;
   if Read_Type in ('01', '02') then output Table_A;
   else output Table_B;
run;

View solution in original post

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26
data want1 want2;
  set have;
  if read_type in (1,2) output want1;
  else output want2;
run;
MRB3855
Fluorite | Level 6

This should do the trick.

data want12;
 set have;
 where read_type<3;
run;
data want34;
 set have;
 where read_type>2;
run;
Kurt_Bremser
Super User

In such cases I very much prefer to use a select statement:

data
  want1
  want2
;
set have;
select (read_type);
  when (1,2) output want1;
  when (3,4) output want2;
end;
run;

If a value outside the given range 1-4 is encountered, the step will fail, alerting you to the unexpected value.

dassuz
Calcite | Level 5

Hi I was hoping someone can help me, I have a table with many columns, One of the columns is called Read_Type, This column has millions of lines of data which consists of either a 01, 02, 03 or a zero 4. I would like to transfer all the data with a read type of 01 and 02 into Table_A and the remainder into Table_B, what is the best way to do this

PeterClemmensen
Tourmaline | Level 20

Do like this

 

data Table_A Table_B;
   set have;
   if Read_Type in ('01', '02') then output Table_A;
   else output Table_B;
run;
dassuz
Calcite | Level 5
Thanks
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why not start by following the guidance on posting a question.  Post test data in the form of a datastep:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Show what you want the output to be.  

 

You say in the first post you have 1,2,3,4.  In this you say you have 01, 02, 03, 04 or 0, so is that a character variable?

Second, what is wrong with the code examples you have been given so far?

Kurt_Bremser
Super User

Just replace the values in my when-branches with the correct character values.


@dassuz wrote:

Hi I was hoping someone can help me, I have a table with many columns, One of the columns is called Read_Type, This column has millions of lines of data which consists of either a 01, 02, 03 or a zero 4. I would like to transfer all the data with a read type of 01 and 02 into Table_A and the remainder into Table_B, what is the best way to do this


 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 8270 views
  • 0 likes
  • 5 in conversation