Help using Base SAS procedures

How do I solve this query.....

Reply
Occasional Contributor
Posts: 13

How do I solve this query.....

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..
Regular Contributor
Posts: 229

Re: How do I solve this query.....

proc transpose data=b out=c(drop=_NAME_);
by custid ;
run;


And u can rename the remaniing varaibles col1=emp1 col2=emp2 col3=emp3
Occasional Contributor
Posts: 13

Re: How do I solve this query.....

As I told you i don't want to use proc transpose...thanks
Super User
Posts: 9,682

Re: How do I solve this query.....

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
Occasional Contributor
Posts: 13

Re: How do I solve this query.....

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,
Respected Advisor
Posts: 3,777

Re: How do I solve this query.....

Your specification is ambiguous.

Is EMP1 in CUSTID 1 the same as EMP1 in CUSTID 2, and in your real data are they equal.
Occasional Contributor
Posts: 13

Re: How do I solve this query.....

Hi,

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

Thanks Again.....
Super User
Posts: 9,682

Re: How do I solve this query.....

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
Ask a Question
Discussion stats
  • 7 replies
  • 187 views
  • 0 likes
  • 4 in conversation