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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 899 views
  • 1 like
  • 3 in conversation