BookmarkSubscribeRSS Feed
JillChen0131
Fluorite | Level 6

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;

4 REPLIES 4
ballardw
Super User

Group for what purpose? Graph? Count or other summary? Report?

JillChen0131
Fluorite | Level 6

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. 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 456 views
  • 0 likes
  • 4 in conversation