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

Hello,

 

I have data where people (cases) are clustered in groups. I want to randomly select 1 case from each cluster and use only selected cases in the further analysis. (And I want to do this process many times). Is there a simple way to do that? Any suggestions would be very much appreciated.

 

Thank you in advance.

 

P.S. So far I understood how to select the first or last case in a cluster but in my situation I need to select a case randomly.

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
Community_Guide
SAS Moderator

Hello @Amanda_Lemon,


Your question requires more details before experts can help. Can you revise your question to include more information? 

 

Review this checklist:

  • Specify a meaningful subject line for your topic.  Avoid generic subjects like "need help," "SAS query," or "urgent."
  • When appropriate, provide sample data in text or DATA step format.  See this article for one method you can use.
  • If you're encountering an error in SAS, include the SAS log or a screenshot of the error condition. Use the Photos button to include the image in your message.
    use_buttons.png
  • It also helps to include an example (table or picture) of the result that you're trying to achieve.

To edit your original message, select the "blue gear" icon at the top of the message and select Edit Message.  From there you can adjust the title and add more details to the body of the message.  Or, simply reply to this message with any additional information you can supply.

 

edit_post.png

SAS experts are eager to help -- help them by providing as much detail as you can.

 

This prewritten response was triggered for you by fellow SAS Support Communities member @mkeintz

.
SuryaKiran
Meteorite | Level 14

Please provide some sample data in Data step and the output your looking for.

 

You can your macros to do repetitive work. You can use CALL SYMPUT on condition to hold the values in macros and call them later. Also check RAND function.

Thanks,
Suryakiran
Amanda_Lemon
Quartz | Level 8

Thank you for your reply. My data look something like this:

 

ID   Cluster Var1 Var2

1          1        2       3

2          1        1       5

3          2        4       4

4          2        6       2

5          2        1       3

6          3        4       1

7          4        4       6

8          4        7       3

9          4        5       5

10        4        2       1

...

 

Each case (as indicated by ID) is clustered. For example, Cases 1 and 2 are clustered within Cluster 1; Cases 3, 4, and 5 are clustered within Cluster 2, Case 6 is the only case in Cluster 3; and Cases 7-10 are clustered within Cluster 4. I also have values for each case on Var1 and Var2.

 

What I want to do is to select randomly 1 case per cluster. So, after selection, I will have a data set of 4 cases, each belonging to a unique cluster. After that, I will use this newly formed data set to work with Var1 and Var2, e.g., test for mean differences between Var1 and Var2. 

 

I understand how to do repetitive work -- I can just have a loop. Also, the RAND statement, I believe, will not help me as I am not generating data -- I already have data from which I just need to randomly select 1 case per cluster.

 

Thank you in advance.

data_null__
Jade | Level 19
PROC SURVEYSELECT
Amanda_Lemon
Quartz | Level 8
THANK YOU! I knew there got to be an easy way to do that. 🙂

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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