BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dan999
Fluorite | Level 6

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     

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

View solution in original post

5 REPLIES 5
Haikuo
Onyx | Level 15

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

dan999
Fluorite | Level 6

That works. Thank you Haikuo.

Astounding
PROC Star

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.

Cynthia_sas
SAS Super FREQ

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;


proc_report_order_usage.jpg
dan999
Fluorite | Level 6

It is a dataset that I'm interested in but I'll keep this for future reference. Thank you.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2001 views
  • 3 likes
  • 4 in conversation