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

I have a data set that has multiple variable with observations, I want to group the a particular variable observations. 

 

Ex - 

SubjID  Order   ROI    VISIT .....

XXX        1        ROI1    baseline 

XXX       1          ROI1    Screening

XXZ        2        ROI2    baseline 

XXZ       2          ROI2    screening 

XZX       3       ROI3     baseline 

XZX       3        ROI3   screening 

 

 

I am wishing to get result like this 

 

SubjID    ROI    VISIT .....

XXX       ROI1    baseline 

                           Screening

XXZ       ROI2    baseline 

                           Screening

XZX      ROI3     baseline 

                           Screening

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You wouldn't usually do this in a data set. You would do this for a printed or displayed report and you can get it either by setting it as a GROUP variable in PROC REPORT or in PROC TABULATE.

 

If you really want it in a data set, use FIRST and BY group processing to set anything not first to missing.

 

by subjid order roi;
if not first.roi then call missing(roi);
if not first.subjid then call missing(subjid);

@shanky_44 wrote:

I have a data set that has multiple variable with observations, I want to group the a particular variable observations. 

 

Ex - 

SubjID  Order   ROI    VISIT .....

XXX        1        ROI1    baseline 

XXX       1          ROI1    Screening

XXZ        2        ROI2    baseline 

XXZ       2          ROI2    screening 

XZX       3       ROI3     baseline 

XZX       3        ROI3   screening 

 

 

I am wishing to get result like this 

 

SubjID    ROI    VISIT .....

XXX       ROI1    baseline 

                           Screening

XXZ       ROI2    baseline 

                           Screening

XZX      ROI3     baseline 

                           Screening


 


@shanky_44 wrote:

I have a data set that has multiple variable with observations, I want to group the a particular variable observations. 

 

Ex - 

SubjID  Order   ROI    VISIT .....

XXX        1        ROI1    baseline 

XXX       1          ROI1    Screening

XXZ        2        ROI2    baseline 

XXZ       2          ROI2    screening 

XZX       3       ROI3     baseline 

XZX       3        ROI3   screening 

 

 

I am wishing to get result like this 

 

SubjID    ROI    VISIT .....

XXX       ROI1    baseline 

                           Screening

XXZ       ROI2    baseline 

                           Screening

XZX      ROI3     baseline 

                           Screening


 

View solution in original post

2 REPLIES 2
Reeza
Super User

You wouldn't usually do this in a data set. You would do this for a printed or displayed report and you can get it either by setting it as a GROUP variable in PROC REPORT or in PROC TABULATE.

 

If you really want it in a data set, use FIRST and BY group processing to set anything not first to missing.

 

by subjid order roi;
if not first.roi then call missing(roi);
if not first.subjid then call missing(subjid);

@shanky_44 wrote:

I have a data set that has multiple variable with observations, I want to group the a particular variable observations. 

 

Ex - 

SubjID  Order   ROI    VISIT .....

XXX        1        ROI1    baseline 

XXX       1          ROI1    Screening

XXZ        2        ROI2    baseline 

XXZ       2          ROI2    screening 

XZX       3       ROI3     baseline 

XZX       3        ROI3   screening 

 

 

I am wishing to get result like this 

 

SubjID    ROI    VISIT .....

XXX       ROI1    baseline 

                           Screening

XXZ       ROI2    baseline 

                           Screening

XZX      ROI3     baseline 

                           Screening


 


@shanky_44 wrote:

I have a data set that has multiple variable with observations, I want to group the a particular variable observations. 

 

Ex - 

SubjID  Order   ROI    VISIT .....

XXX        1        ROI1    baseline 

XXX       1          ROI1    Screening

XXZ        2        ROI2    baseline 

XXZ       2          ROI2    screening 

XZX       3       ROI3     baseline 

XZX       3        ROI3   screening 

 

 

I am wishing to get result like this 

 

SubjID    ROI    VISIT .....

XXX       ROI1    baseline 

                           Screening

XXZ       ROI2    baseline 

                           Screening

XZX      ROI3     baseline 

                           Screening


 

shanky_44
Obsidian | Level 7

Thanks Reeza, 

 

Thanks that worked, although my problem is more complex but your answer helped me to understand the concept. Appreciate your help!

 

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
  • 2 replies
  • 2267 views
  • 2 likes
  • 2 in conversation