BookmarkSubscribeRSS Feed
tom16
Calcite | Level 5
I have data set like this:

data b;
input custid emp $ age;
cards;
01 emp1 20
01 emp2 30
01 emp3 40
02 emp1 50
02 emp2 60
02 emp3 70
03 emp1 80
03 emp2 90
03 emp3 20
;
run;
and I wan to make it like this:
custid emp1 emp2 emp3 ;
01 20 30 40
02 50 60 70
03 80 90 20
;
I don't want to use Proc transpose....how can I do this........Please give quary..
7 REPLIES 7
R_Win
Calcite | Level 5
proc transpose data=b out=c(drop=_NAME_);
by custid ;
run;


And u can rename the remaniing varaibles col1=emp1 col2=emp2 col3=emp3
tom16
Calcite | Level 5
As I told you i don't want to use proc transpose...thanks
Ksharp
Super User
Although you do not want proc transpose (the best choice), then @data step will meet your taste.

[pre]
data b;
input custid emp $ age;
cards;
01 emp1 20
01 emp2 30
01 emp3 40
02 emp1 50
02 emp2 60
02 emp3 70
03 emp1 80
03 emp2 90
03 emp3 20
;
run;
proc sort data=b;
by custid;
run;
data op(drop=count emp age);
set b;
by custid;
array e{3} emp1 emp2 emp3;
retain emp1 emp2 emp3;
if first.custid then count=0;
count+1;
e{count} = age;
if last.custid then output;
run;

proc print noobs;run;
[/pre]



Ksharp
tom16
Calcite | Level 5
Hey KSHARP....

Yesterday I thought mail to you this one....I read your answers before in this forum....this work perfectelly fine.....you are the best...

Thanks,
data_null__
Jade | Level 19
Your specification is ambiguous.

Is EMP1 in CUSTID 1 the same as EMP1 in CUSTID 2, and in your real data are they equal.
tom16
Calcite | Level 5
Hi,

Thanks for yor answer...above ksharp give answer for this one and it work perfectelly fine...

Thanks Again.....
Ksharp
Super User
Hehe.Ok you can mail to me.
And also I think @data _null_; can do it better than me.That is just to post my solution before @data _null_; saw it.


Ksharp

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1318 views
  • 0 likes
  • 4 in conversation