BookmarkSubscribeRSS Feed
Aayushi_17
Quartz | Level 8

Hi all,

In this table how to retain the value of low and high for same subject if the value is ticked.For example please find the table below for refrence.

 

SUBJECTBUN_ND_LABUN_NHIGH_VABUN_NLOW_VACALCIUM_ND_LACALCIUM_NHIGH_VACALCIUM_NLOW_VACREAT_CHNG_LACREAT_NHIGH_VACREAT_NLOW_VA
4001 8.12.1 2.652.15 2.652.15
4001         
4001   ticked  ticked  
4001   ticked  ticked  
4001ticked  ticked     
4001ticked  ticked     
4001ticked  ticked     
4001         
1011         
1016         
3002         
3003   ticked     
3004         
3005       7.22.6
5003ticked  ticked   7.22.6
5003ticked  ticked     
5003   ticked     
5003ticked  ticked     
5003ticked  ticked     
5003 7.22.6   ticked  

 

This how the output should look like :

 

SUBJECTBUN_ND_LABUN_NHIGH_VABUN_NLOW_VACALCIUM_ND_LACALCIUM_NHIGH_VACALCIUM_NLOW_VACREAT_CHNG_LACREAT_NHIGH_VACREAT_NLOW_VA
4001 8.12.1 2.652.15 2.652.15
4001         
4001   ticked2.652.15ticked2.652.15
4001   ticked2.652.15ticked2.652.15
4001ticked8.12.1ticked2.652.15   
4001ticked8.12.1ticked2.652.15   
4001ticked8.12.1ticked2.652.15   
4001         
1011         
1016         
3002         
3003   ticked     
3004         
3005       7.22.6
5003ticked7.22.6ticked2.652.15 7.22.6
5003ticked7.22.6ticked2.652.15   
5003   ticked2.652.15   
5003ticked7.22.6ticked2.652.15   
5003ticked7.22.6ticked2.652.15   
5003 7.22.6   ticked7.22.6
10 REPLIES 10
PeterClemmensen
Tourmaline | Level 20

What is the logic here?

 

Why does Subject 4001 get the value 8.1 and 5003 the value 7.2?

Aayushi_17
Quartz | Level 8

the values vary with different subject...for eg : for subject 4001 the values is 8.1 and 2.1  which will be same for all 4001 subject if it  'ticked'

Kurt_Bremser
Super User

Please review your expected output. It has 8 observations for 4001, while the source has only 7.

Other subjects (e.g. 1003, 5004) are missing completely.

 


@Aayushi_17 wrote:

Hi all,

In this table how to retain the value of low and high for same subject if the value is ticked.For example please find the table below for refrence.

 

SUBJECT BUN_ND_LA BUN_NHIGH_VA BUN_NLOW_VA CALCIUM_ND_LA CALCIUM_NHIGH_VA CALCIUM_NLOW_VA CREAT_CHNG_LA CREAT_NHIGH_VA CREAT_NLOW_VA
4001   8.1 2.1   2.65 2.15   2.65 2.15
4001                  
4001       ticked     ticked    
4001       ticked     ticked    
4001 ticked     ticked          
4001 ticked     ticked          
4001 ticked     ticked          
1003                  
1011                  
1016                  
3002                  
3003       ticked          
3004                  
3005               7.2 2.6
5003 ticked     ticked       7.2 2.6
5003 ticked     ticked          
5003       ticked          
5003 ticked     ticked          
5003 ticked     ticked          
5003   7.2 2.6       ticked    
5004                  

 

This how the output should look like :

 

SUBJECT BUN_ND_LA BUN_NHIGH_VA BUN_NLOW_VA CALCIUM_ND_LA CALCIUM_NHIGH_VA CALCIUM_NLOW_VA CREAT_CHNG_LA CREAT_NHIGH_VA CREAT_NLOW_VA
4001   8.1 2.1   2.65 2.15   2.65 2.15
4001                  
4001       ticked 2.65 2.15 ticked 2.65 2.15
4001       ticked 2.65 2.15 ticked 2.65 2.15
4001 ticked 8.1 2.1 ticked 2.65 2.15      
4001 ticked 8.1 2.1 ticked 2.65 2.15      
4001 ticked 8.1 2.1 ticked 2.65 2.15      
4001                  
1011                  
1016                  
3002                  
3003       ticked          
3004                  
3005               7.2 2.6
5003 ticked 7.2 2.6 ticked 2.65 2.15   7.2 2.6
5003 ticked 7.2 2.6 ticked 2.65 2.15      
5003       ticked 2.65 2.15      
5003 ticked 7.2 2.6 ticked 2.65 2.15      
5003 ticked 7.2 2.6 ticked 2.65 2.15      
5003   7.2 2.6       ticked 7.2 2.6

 

Aayushi_17
Quartz | Level 8
sorry the data has been updated now
andreas_lds
Jade | Level 19

Is there always exactly one observation having not-missing values for each id? Can you post data in usable form? Usable = a data step with datalines/cards.

Aayushi_17
Quartz | Level 8

Hi andreas_ld
No..sometimes the observation might have missing values also..i have jus given them for refernce purpose

Please find the sample data in usable form below
Data have;
input SUBJECT $ BUN_ND_LA $ BUN_NHIGH_VA $ BUN_NLOW_VA $;
datalines;
4001 8.1 2.1
4001
4001
4001
4001 ticked
4001 ticked
4001 ticked
1003
;
run;

andreas_lds
Jade | Level 19

My fault, i should have been more precise. I meant: is there always only one observation with values for *_NHIGH_VA, *_NLOW_VA etc. for each subject?

And: please check the code you have posted, i got a "lost card" ...

Kurt_Bremser
Super User

When we ask for data in a data step, we mean a data step that works (no ERRORs, WARNINGs or NOTEs) and creates valid data. Please review your code and fix it.

Hint: use an INFILE DATALINES statement with a delimiter (DLM=), DSD and TRUNCOVER.

hhinohar
Quartz | Level 8
According to what is described here,you want nonmissing values retained for each ticked flag per subject.
If I Look at CALCIUM_NHIGH_VA CALCIUM_NLOW_VA for subject 5003, only missing values exist so these observations should be missing.
Is this a typo or your specification?
Can you please ellaborate on that?
mkeintz
PROC Star

For each subject, you apparently have zero or one observation with non-missing BUN_NHIGH_VA  and BUN_NLOW_VA.  For all observations with BUN_ND_LA='ticked" you want to apply those non-missing values.

 

This program is untested.  If you were to provide your sample data in the form of a working data set, then I could vouch for this code:

 


data want;
  set have ;
  by subject notsorted;
  if first.subject then ptr=.;
  if BUN_NHIGH_VA^=. and BUN_NLOW_VA^=. then ptr=_n_;

  if last.subject then do until (last.subject);
    set have;
	by subject notsorted;
	if 	BUN_ND_LA='ticked' and ptr^=. then set have (keep=bun_nhigh_va bun_nlow_va) point=ptr;
	output;
  end;
run;

This reads each group twice.  The first pass is to identify which observation has the non-missing values, setting ptr to the identified obs numbers.  The second pass re-reads the group, and if BUN_ND_LA='ticked' it uses the "point=ptr" option to read the non-missing values prior to the output statement.  Note if a group has non non-missing values, then ptr=. and is not used.

--------------------------
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

--------------------------

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 10 replies
  • 1019 views
  • 0 likes
  • 6 in conversation