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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.