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

I have data like below

ID Custom_flag Variable
1000 H1_Curr 1
1000 H2_Curr 1
1000 H1_Prev 1
2000 H1_Curr 1
2000 H2_Prev 1
2000 H2_Curr 1

 

I need Output like 

ID H1_Curr H2_Curr H1_Prev H2_Prev
1000 1 1 1  
2000 1 1   1

 

I am doing transpose like this

 

proc sort data= bef_have out=bef_have_sort NODUPKEY;
by custom_flag ID;
run; 

proc transpose data= bef_have_sort out = want_data(drop=_name_ _label_);
by id;
id custom_flag;
var variable;
run;


I am getting output like below
ID H1_Curr H2_Curr H1_Prev H2_Prev
1000 1      
1000   1    
1000     1 1
2000 1      
2000   1    
2000       1
I am not sure why this is happening! Help is much appreciated1

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

I am getting an error when i try to execute the proc transpose, sorting by Id and custom_flag should solve the problem.

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

I am getting an error when i try to execute the proc transpose, sorting by Id and custom_flag should solve the problem.

Kurt_Bremser
Super User

Works fine for me:

data have;
input ID $ Custom_flag $ Variable;
datalines;
1000  H1_Curr 1
1000  H2_Curr 1
1000  H1_Prev 1
2000  H1_Curr 1
2000  H2_Prev 1
2000  H2_Curr 1
;

proc transpose data=have out=want (drop=_name_);
by id;
id custom_flag;
var variable;
run;

proc print data=want noobs;
run;

Result:

ID	H1_Curr	H2_Curr	H1_Prev	H2_Prev
1000	1	1	1	.
2000	1	1	.	1

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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