If I pull data that looks like this:
ID Name Gender Date
1 Dan M 1/1/2012
1 Dan M 12/23/2011
1 Dan M 10/15/2011
1 Dan M 9/17/2011
2 Carol F 8/12/2011
2 Carol F 7/15/2011
is there a way to make it display like this:
ID Name Gender Date
1 Dan M 1/1/2012
1 12/23/2011
1 10/15/2011
1 9/17/2011
2 Carol F 8/12/2011
2 7/15/2011
I want to not display most repeating data except for the ID so if the data gets sorted a different way they can always get back to the original. I think I read about a way to do this but now I can't find where I read it.
Thanks
Try this:
data have;
input (id Name Gender Date) (:$10.);
cards;
1 Dan M 1/1/2012
1 Dan M 12/23/2011
1 Dan M 10/15/2011
1 Dan M 9/17/2011
2 Carol F 8/12/2011
2 Carol F 7/15/2011
;
data want;
set have;
by id;
name=ifc(first.id,name,' ');
gender=ifc(first.id,gender,' ');
run;
Regards,
Haikuo
Try this:
data have;
input (id Name Gender Date) (:$10.);
cards;
1 Dan M 1/1/2012
1 Dan M 12/23/2011
1 Dan M 10/15/2011
1 Dan M 9/17/2011
2 Carol F 8/12/2011
2 Carol F 7/15/2011
;
data want;
set have;
by id;
name=ifc(first.id,name,' ');
gender=ifc(first.id,gender,' ');
run;
Regards,
Haikuo
That works. Thank you Haikuo.
Take a look at the ID statement within PROC PRINT.
Also consider whether you want the variable named ID to repeat or to print just once.
Good luck.
Hi:
The posted solution will create a DATASET with the desired change. However, if all you want is a REPORT -- such as an HTML, RTF, PDF, etc, report, then PROC REPORT will do what you want without making an extra copy of the data.
cynthia
data fakedata;
infile datalines;
input idvar Name $ Gender $ Date : mmddyy10.;
return;
datalines;
1 Dan M 9/17/2011
1 Dan M 5/14/2010
1 Dan M 1/1/2012
1 Dan M 12/23/2011
1 Dan M 10/15/2011
2 Carol F 8/12/2011
2 Carol F 7/15/2011
3 Fred M 5/15/2011
3 Fred M 11/15/2011
3 Fred M 12/28/2011
;
run;
proc sort data=fakedata;
by idvar name gender descending date ;
run;
ods html file='c:\temp\report.html';
proc report data=fakedata nowd;
column idvar name gender date;
define idvar / display 'ID';
define Name / order 'Name' order=data;
define Gender / order 'Gender' order=data;
define date / order order=data f=mmddyy10.;
run;
ods html close;
It is a dataset that I'm interested in but I'll keep this for future reference. Thank you.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.