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
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.
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.
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.
Thanks for all of your great suggestion.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.