BookmarkSubscribeRSS Feed
shubham_d
Fluorite | Level 6

Have - 

idnum1num2num3
1101102103

 

data d1;

input id num1 num2 num3;

datalines;

1 101 102 103

;

run;

 

Want - 

 

idnum_list
1101
1102
1103


Incase either of num1, num2, num3 is null then I don't want their entries in the dataset. For example - If num3 is null then dataset should be -

 

idnum_list
1101
1102


Thanks in advance 🙂 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Easiest thing to do is simply delete the unwanted rows from the output.

--
Paige Miller
shubham_d
Fluorite | Level 6
Hey! Deleting unwanted rows is fine. But how would I transpose keeping the ID same & creating a new column for this transpose? Basically the dataset of Want
PaigeMiller
Diamond | Level 26

Run PROC TRANSPOSE with the following in the code

 

by id;

 

 

 

--
Paige Miller
Tom
Super User Tom
Super User

@shubham_d wrote:
Hey! Deleting unwanted rows is fine. But how would I transpose keeping the ID same & creating a new column for this transpose? Basically the dataset of Want

You probably need to make more test data that actually demonstrates the issues you are having (or are worried about).

 

If you want the re-transposed data to end up in the same variable names then you need to either keep the _NAME_ variable that PROC TRANSPOSE generates (or something that can be used to re-create it) to use in the ID statement of PROC TRANSPOSE.

proc transpose data=have out=TALL(where=(not missing(col1)) ;
   by id;
   var var1-var3 ;
run;
proc tranpose data=TALL out=WIDE(drop=_name_);
  by id;
  id _name_;
  var col1;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1140 views
  • 0 likes
  • 3 in conversation