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

Hello:

I would like to group with years.   Please suggest how.

 

 

data test; 
      infile datalines dlm='|'; 
  input ID  Year State : $10.; 
datalines;                  
300012556 | 1998 |  GA |   
300012956 | 1985 |  IA |   
300012586 | 1963 |  CA |  
300052586 | 1997 |  TX | 
300052576 | 1999 |  OH |   
300052577 | 1999 |  TX |   
300052578 | 1999 |  NY |  
300012578 | 1998 |  NV |  
300012878 | 1999 |  FL | 
300022578 | 1985 |  PA |   
; 

Proc sort; by year; run;

 

 

 

 

My result would like to be:

Year       ID                       State

1963     300012586          CA

1985     300012956          IA

             300022578          PA

1997     300052586          TX

1998     300012556          GA

             300012578          NV

1999     300052576          OH

             300052577          TX

             300052578          NY

             300012878          FL

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

It looks like you want a REPORT not a dataset.

 

proc report data=test nowd;
   column year id state;
   define year /group;
   define id/display;
   define state/display;
run;

If you do want a data set it really makes much more sense to keep the year on each record, such as building reports like this.

 

View solution in original post

3 REPLIES 3
ballardw
Super User

It looks like you want a REPORT not a dataset.

 

proc report data=test nowd;
   column year id state;
   define year /group;
   define id/display;
   define state/display;
run;

If you do want a data set it really makes much more sense to keep the year on each record, such as building reports like this.

 

mkeintz
PROC Star

You've sorted the data by year  (although you may want to sort "by year state").  And now you want to report it with each year posted only for its first instance.

 

Look at PROC PRINT,  with the BY statement, and the ID statement.  Show us what your found that works, and mark your own successful answer as the solution.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ybz12003
Rhodochrosite | Level 12

Thanks for all of your great suggestion.

sas-innovate-2024.png

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.

 

Register now!

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
  • 3 replies
  • 654 views
  • 1 like
  • 3 in conversation