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

I have a table that looks like this and I want a the variable status to be split into two with one variable containing only "1" and the 2nd variable containing "2 and 3"

 

ID Status
1 1
1 3
1 1
1 1
2 1
2 3
2 1
3 1
3 2

 

I want the result to look like this table below

ID 1st Status 2nd Status
1 1  
1   3
1 1  
1 1  
2 1  
2   3
2 1  
3 1  
3   2
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

It might help to describe how you intend to use the reshaped data. You may be adding unneeded complexity with additional variables.

 

Data want;

   set have;

   if status = 1 then Status1 = 1;

   else if status in (2,3) then  status2 = status;

run;

 

maybe. "1st status" is not legal for variable names.

If you no longer want the Status variable in the data set then drop it.

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20
data have;
input ID Status;
datalines;
1 1
1 3
1 1
1 1
2 1
2 3
2 1
3 1
3 2
;

data want;
   set have;
   if status = 1 then _1stStatus = Status;
   else if Status in (2, 3) then _2ndStatus = Status;
   drop Status;
run;
ballardw
Super User

It might help to describe how you intend to use the reshaped data. You may be adding unneeded complexity with additional variables.

 

Data want;

   set have;

   if status = 1 then Status1 = 1;

   else if status in (2,3) then  status2 = status;

run;

 

maybe. "1st status" is not legal for variable names.

If you no longer want the Status variable in the data set then drop it.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 620 views
  • 2 likes
  • 3 in conversation