I need to group the dataset by different ways. (1) within the same test, visitnum 101 and 108 should be in the same group, other visitnums in their own group. (2) every different test + visitnum in a group. (3) every test in a group. These 3 ways can be done separately. Sample dataset as below:
data have;
input test$ visitnum ord seq;
datalines;
aa 101 0 0
aa 101 0 1
aa 101 0 2
aa 101 0 3
aa 101 0 4
aa 108 1 0
aa 108 1 1
aa 108 1 2
aa 108 1 3
aa 108 1 4
aa 108 2 0
aa 108 2 1
aa 108 2 2
aa 108 2 3
aa 108 2 4
aa 115 1 0
aa 115 1 1
aa 115 1 2
aa 115 1 3
aa 115 1 4
aa 115 2 0
aa 115 2 1
aa 115 2 2
aa 115 2 3
aa 115 2 4
bb 101 0 0
bb 101 0 1
bb 101 0 2
bb 101 0 3
bb 101 0 4
bb 108 1 0
bb 108 1 1
bb 108 1 2
bb 108 1 3
bb 108 1 4
bb 108 2 0
bb 108 2 1
bb 108 2 2
bb 108 2 3
bb 108 2 4
bb 115 1 0
bb 115 1 1
bb 115 1 2
bb 115 1 3
bb 115 1 4
bb 115 2 0
bb 115 2 1
bb 115 2 2
bb 115 2 3
bb 115 2 4
;
run;
If you need this in a stat procedure, try a multilabel format.
Group for what purpose? Graph? Count or other summary? Report?
It is for a summary and table output. Need to assign group based on the test and visitnum, but visitnum 101 and 108 need to be in the same group.
For #1, create a custom format
proc format;
value visitf 101,108='101 and 108';
run;
and then assign format visitf. to the variable VISITNUM when you create your analysis, table or graph.
For #2 and #3, it really depends on the report, analysis or graph you are trying to make. I don't think formatting is needed, but we do need more specifics about the report, analysis or graph. For example, if you are just doing a report by variable TEST, I don't think pre-grouping is needed here, PROC REPORT knows how to handle and generate reports where the table is grouped by variable TEST.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.