Dear Experts,
I want to visualize my data as a horizontal format with summing the year value.
For example :
data lkj;
input ID yearof;
cards;
132 2004
132 2004
132 2005
321 2010
321 2010
321 2015
run;
Required OP
ID | 2004 | 2005 | 2010 | 2015 |
132 | 2 | 1 | . | . |
321 | . | . | 2 | 1 |
Kindly help me to transform in the given format.
Thanks in advance!
proc report data=lkj;
columns id yearof;
define id/group;
define yearof/across;
run;
By the way, this is counting, not summing.
proc report data=lkj;
columns id yearof;
define id/group;
define yearof/across;
run;
By the way, this is counting, not summing.
proc sql;
create table temp as
select *,
count(*) as count
from lkj
group by ID, yearof;
quit;
proc transpose data=temp out=want(drop=_NAME_) prefix=_;
by ID;
id yearof;
var count;
run;
It is best tool for PROC TABULATE.
data lkj;
input ID yearof;
cards;
132 2004
132 2004
132 2005
321 2010
321 2010
321 2015
;
proc tabulate data=lkj;
class id yearof;
table id,yearof*n=' '*f=best.;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.