BookmarkSubscribeRSS Feed
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Using SAS 9.4

 

I have a data set with measurements at different time points

Pre

2wk

6wk

 

Within each time point their are two groups of measurements SL and CL and in each group their are 20 measurements. 

So time point Pre has 20 SL measurements and 20 CL measurements- 40 total measurements (the same is true of 2wk and 6wk)

 

Now, each of these measurements does not have data in, ie some are blank. 

 

I need to have the same number of measurements in Pre SL/CL as 2wk SL/CL as 6wk SL/CL by each individual row in the data set.

 

Example, row 1 has Pre SL- 12 measurements Pre-CL 10 Measurements, 2wk-SL- 14 measurements 2wk CL-12 Measurements, 6wk-SL 14 measuremnts, 6wk-CL 12 measurements

 

I need the lowest number of measurements of each group (SL and CL) to be added together for this row. From the example above SL-12 measurements and CL-10 measurements added together to get a total SL and a total CL for all 3 time points.

 

Where I am struggling is each row will be different as to the number of measurements that are completed in the SL and CL groups but I still need the lowest number of measurements per group (SL and CL) per row. 

 

If this does not make sense I can attempt to explain differently but any thoughts on how to go about this would be greatly appreciated. Thank you

6 REPLIES 6
SuryaKiran
Meteorite | Level 14

Hello,

 

Please put some effort to create a sample data you have and your desired output from the description you stated so it makes easy for us to understand and fast responses. 

 

Please provide sample data.

Thanks,
Suryakiran
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7
sl_mcpjointssl_thump_mcpsl_wristsl_wrist_4cmsl_wrist_8cmsl_wrist_12cmsl_wrist_16cmsl_wrist_20cmsl_wrist_24cmsl_wrist_28cmsl_wrist_32cmsl_elbow_creasesl_elbow_4cmsl_elbow_8cmsl_elbow_12cmsl_elbow_16cmsl_elbow_20cmsl_elbow_24cmsl_elbow_28cmsl_elbow_32cm
18.518.815.214.816.720.522.924.2   23.626.629.430.7     
                    
cl_mcpjointscl_thump_mcpcl_wristcl_wrist_4cmcl_wrist_8cmcl_wrist_12cmcl_wrist_16cmcl_wrist_20cmcl_wrist_24cmcl_wrist_28cmcl_wrist_32cmcl_elbow_creasecl_elbow_4cmcl_elbow_8cmcl_elbow_12cmcl_elbow_16cmcl_elbow_20cmcl_elbow_24cmcl_elbow_28cmcl_elbow_32cm
17.61815.31517.220.222.923.9   24.326.529.330.8     
                    
p_sl_mcpjoints_2wkp_sl_thump_mcp_2wkp_sl_wrist_2wkp_sl_wrist_4cm_2wkp_sl_wrist_8cm_2wkp_sl_wrist_12cm_2wkp_sl_wrist_16cm_2wkp_sl_wrist_20cm_2wkp_sl_wrist_24cm_2wkp_sl_wrist_28cm_2wkp_sl_wrist_32cm_2wkp_sl_elbow_crease_2wkp_sl_elbow_4cm_2wkp_sl_elbow_8cm_2wkp_sl_elbow_12cm_2wkp_sl_elbow_16cm_2wkp_sl_elbow_20cm_2wkp_sl_elbow_24cm_2wkp_sl_elbow_28cm_2wkp_sl_elbow_32cm_2wk
19.219.715.515.11720.123.324   23.526.529.330.8     
                    
p_cl_mcpjoints_2wkp_cl_thump_mcp_2wkp_cl_wrist_2wkp_cl_wrist_4cm_2wkp_cl_wrist_8cm_2wkp_cl_wrist_12cm_2wkp_cl_wrist_16cm_2wkp_cl_wrist_20cm_2wkp_cl_wrist_24cm_2wkp_cl_wrist_28cm_2wkp_cl_wrist_32cm_2wkp_cl_elbow_crease_2wkp_cl_elbow_4cm_2wkp_cl_elbow_8cm_2wkp_cl_elbow_12cm_2wkp_cl_elbow_16cm_2wkp_cl_elbow_20cm_2wkp_cl_elbow_24cm_2wkp_cl_elbow_28cm_2wkp_cl_elbow_32cm_2wk
17.618.61515.117.320.72324   23.826.32929.8     
                    
p_sl_mcpjoints_6wkp_sl_thump_mcp_6wkp_sl_wrist_6wkp_sl_wrist_4cm_6wkp_sl_wrist_8cm_6wkp_sl_wrist_12cm_6wkp_sl_wrist_16cm_6wkp_sl_wrist_20cm_6wkp_sl_wrist_24cm_6wkp_sl_wrist_28cm_6wkp_sl_wrist_32cm_6wkp_sl_elbow_crease_6wkp_sl_elbow_4cm_6wkp_sl_elbow_8cm_6wkp_sl_elbow_12cm_6wkp_sl_elbow_16cm_6wkp_sl_elbow_20cm_6wkp_sl_elbow_24cm_6wkp_sl_elbow_28cm_6wkp_sl_elbow_32cm_6wk
1818.915.315.216.719.922.724   2426.12829.9     
                    
p_cl_mcpjoints_6wkp_cl_thump_mcp_6wkp_cl_wrist_6wkp_cl_wrist_4cm_6wkp_cl_wrist_8cm_6wkp_cl_wrist_12cm_6wkp_cl_wrist_16cm_6wkp_cl_wrist_20cm_6wkp_cl_wrist_24cm_6wkp_cl_wrist_28cm_6wkp_cl_wrist_32cm_6wkp_cl_elbow_crease_6wkp_cl_elbow_4cm_6wkp_cl_elbow_8cm_6wkp_cl_elbow_12cm_6wkp_cl_elbow_16cm_6wkp_cl_elbow_20cm_6wkp_cl_elbow_24cm_6wkp_cl_elbow_28cm_6wkp_cl_elbow_32cm_6wk
1718.314.815.317.520.722.823.8   23.826.629.429.5     

 

This is what the data looks like but in a wide format. This one isn't a great example because the numbers line up but you can count that there are 12 measurements in each of the 6 rows (put into rows to show they are their own group). I need to add each one to create a total for that row. Where this becomes more difficult is not all of the rows will have the same number of measurements (ie the SL at pre could have 12 measurements, at 2wk have 10 measurements and at 6wk have 12 measurement; in this case I would want to add only 10 measurements for pre/2wk/6wk and not include measurements 11 and 12 from the pre and 6 wk time points). Does this help to clarify the question?

mkeintz
PROC Star

 

  1. By "lowest number of measurements" do you want the lowest count of valid (non-missing) measures, or do you want the number of measures that are valid in all three time points?

  2. Do you have an ID variable, such that each ID has three time-points (i.e. 3 observations) with sets of measurements?  If so, are you looking for "lowest number of measurements " for each ID, or for the entire sample?

  3. What do your want the results to look like?  Presumably your starting data set has 42 variables (ID plus time-of-measures plus two sets of 20 measurement variables), and 3 observations per ID.   What does the resulting data set look like, or the resulting report?
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

1. I want a count at each time point of the non-missing measurements

2. I have an ID for each row so each ID has 3 sets of measurements

3. The finish product will be to add the non-missing values together to get a summation but it needs to be the same count of measurements that go into the summation (meaning Pre SL/CL count cannot be 12 measurements and 2 wk be so other number besides 12). I need the same count of measurements for each group and time point to be added together

mkeintz
PROC Star

I asked:

 

  1. By "lowest number of measurements" do you want the lowest count of valid (non-missing) measures, or do you want the number of measures that are valid in all three time points?

    @GS2 wrote:

    1. I want a count at each time point of the non-missing measurements

    I don't see how this answers my question.  (Admittedly I should have asked "or do you want the subset of measures that are valid in all three time points?").


  2. Do you have an ID variable, such that each ID has three time-points (i.e. 3 observations) with sets of measurements?  If so, are you looking for "lowest number of measurements " for each ID, or for the entire sample?


    @GS2 wrote:

    2. I have an ID for each row so each ID has 3 sets of measurements

    This answer the first part, but crucially not the second part.


  3. What do your want the results to look like?  Presumably your starting data set has 42 variables (ID plus time-of-measures plus two sets of 20 measurement variables), and 3 observations per ID.   What does the resulting data set look like, or the resulting report?

    @GS2 wrote:

    3. The finish product will be to add the non-missing values together to get a summation but it needs to be the same count of measurements that go into the summation (meaning Pre SL/CL count cannot be 12 measurements and 2 wk be so other number besides 12). I need the same count of measurements for each group and time point to be added together


OK.  I think ;you want the process to be done for each ID independently rather than for the whole sample.

 

Now, ala your example, if for a given ID, Pre SL/CL and 6WK each have 12 measurements, and 2WK has 6 measurements, are you saying to ignore that ID?  Or if that ID is not to be ignored, then presumably you want the sum of 6 values for each time point.   Which 6 of the 12 values do you want to use?  After all, 6 is the lowest number of measurements.

 

This is why it would be good if you had more comprehensively provided sample data, in the form of a data step, in response to  @SuryaKiran's request.  That will help us help you.

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

I asked:

 

  1. By "lowest number of measurements" do you want the lowest count of valid (non-missing) measures, or do you want the number of measures that are valid in all three time points?
    @GS2 wrote:

    1. I want a count at each time point of the non-missing measurements

    I don't see how this answers my question.  (Admittedly I should have asked "or do you want the subset of measures that are valid in all three time points?").

    Response: I want to know what the lowest number of measurements is at each time point and by group (SL/CL) from there I want to be able to sum the lowest count of measurements for each ID (ie row). There will be some IDs with different 'lowest number of measurements' 
  2. Do you have an ID variable, such that each ID has three time-points (i.e. 3 observations) with sets of measurements?  If so, are you looking for "lowest number of measurements " for each ID, or for the entire sample?

    @GS2 wrote:

    2. I have an ID for each row so each ID has 3 sets of measurements

    This answer the first part, but crucially not the second part.

    Response: The lowest number of measurements for each ID (ie row) is what I am after and then how to add the different number of measurements together by ID
  3. What do your want the results to look like?  Presumably your starting data set has 42 variables (ID plus time-of-measures plus two sets of 20 measurement variables), and 3 observations per ID.   What does the resulting data set look like, or the resulting report?
    @GS2 wrote:

    3. The finish product will be to add the non-missing values together to get a summation but it needs to be the same count of measurements that go into the summation (meaning Pre SL/CL count cannot be 12 measurements and 2 wk be so other number besides 12). I need the same count of measurements for each group and time point to be added together

OK.  I think ;you want the process to be done for each ID independently rather than for the whole sample.

 

Now, ala your example, if for a given ID, Pre SL/CL and 6WK each have 12 measurements, and 2WK has 6 measurements, are you saying to ignore that ID?  Or if that ID is not to be ignored, then presumably you want the sum of 6 values for each time point.   Which 6 of the 12 values do you want to use?  After all, 6 is the lowest number of measurements.

 

Response: Yes, from the example I want the 6 measurements for each timepoint (pre/2wk/6wk) and  group (SL/CL). I would want the first 6 measurements, the way the data is ordered you would not have measurement 2 without first having measurement 1 and so on. 

 

This is why it would be good if you had more comprehensively provided sample data, in the form of a data step, in response to  @SuryaKiran's request.  That will help us help you.

 

Response: I did the best I could but companies do have restriction so I provided as best as I am allowed. Thank you for any help! 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1238 views
  • 0 likes
  • 3 in conversation