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!

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 2847 views
  • 2 likes
  • 2 in conversation