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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.