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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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