BookmarkSubscribeRSS Feed
Mastanvali
Calcite | Level 5

Hi Team,

 

I have the data like below:

SubjectFolderNameFolderSeqVSTEMPVSTPTcount
101Screening1.037.1Supine1
101Day 12.036.9Supine1
101Day 85.036.8Supine1
101Day 156.037.1Supine1
101Day 227.036.7Supine1
101Day 298.036.9Supine1
101Day 369.036.9Supine2
101Day 43 / ET10.036.8Supine1
101Safety Follow-Up12.036.6Supine1
102Screening1.036.8Supine1
102Day 12.036.8Supine2
102Day 85.036.8Supine3
102Day 156.037.0Supine1
102Day 227.037.1Supine1
102Day 298.036.9Supine1
102Day 369.037.0Supine1
102Day 43 / ET10.037.0Supine2
102Safety Follow-Up12.036.9Supine1

 

I am want like below, i tried m in data step but its not working.

SubjectFolderNameFolderSeqVSTEMPVSTPTcountSub_cnt
101Screening1.037.1Supine11
101Day 12.036.9Supine11
101Day 85.036.8Supine11
101Day 156.037.1Supine11
101Day 227.036.7Supine11
101Day 298.036.9Supine12
101Day 369.036.9Supine22
101Day 43 / ET10.036.8Supine11
101Safety Follow-Up12.036.6Supine11
102Screening1.036.8Supine13
102Day 12.036.8Supine23
102Day 85.036.8Supine33
102Day 156.037.0Supine11
102Day 227.037.1Supine11
102Day 298.036.9Supine11
102Day 369.037.0Supine12
102Day 43 / ET10.037.0Supine22
102Safety Follow-Up12.036.9Supine11
6 REPLIES 6
andreas_lds
Jade | Level 19

Please post the data as data steps using datalines and describe the rules that want applied. If you have tried something, post the code you have, so that we can suggest corrections.

 

Mastanvali
Calcite | Level 5
Hi,

Data d;
infile datalines;
input Subject FolderName :$20. FolderSeq VSTEMP VSTPT:$10.;
dataline;
101 Screening 1.0 37.1 Supine
101 Day 1 2.0 36.9 Supine
101 Day 8 5.0 36.8 Supine
101 Day 15 6.0 37.1 Supine
101 Day 22 7.0 36.7 Supine
101 Day 29 8.0 36.9 Supine
101 Day 36 9.0 36.9 Supine
101 Day 43 / ET 10.0 36.8 Supine
101 Safety Follow-Up 12.0 36.6 Supine
102 Screening 1.0 36.8 Supine
102 Day 1 2.0 36.8 Supine
102 Day 8 5.0 36.8 Supine
102 Day 15 6.0 37.0 Supine
102 Day 22 7.0 37.1 Supine
102 Day 29 8.0 36.9 Supine
102 Day 36 9.0 37.0 Supine
102 Day 43 / ET 10.0 37.0 Supine
102 Safety Follow-Up 12.0 36.9 Supine
run;

I did the below logic:
proc sort data=d; by subject FolderSeq VSTEMP; run;

data d1;
set d;
by subject folderseq VSTEMP;
retain count;
if first.VSTEMP and first.subject then count=1;
if VSTEMP=lag(VSTEMP) and subject=lag(subject) then count=count+1;
else count=1;
run;
proc sort data=base2; by subject folderseq VSTEMP; run;

got the output like:

Subject FolderName FolderSeq VSTEMP VSTPT count
101 Screening 1.0 37.1 Supine 1
101 Day 1 2.0 36.9 Supine 1
101 Day 8 5.0 36.8 Supine 1
101 Day 15 6.0 37.1 Supine 1
101 Day 22 7.0 36.7 Supine 1
101 Day 29 8.0 36.9 Supine 1
101 Day 36 9.0 36.9 Supine 2
101 Day 43 / ET 10.0 36.8 Supine 1
101 Safety Follow-Up 12.0 36.6 Supine 1
102 Screening 1.0 36.8 Supine 1
102 Day 1 2.0 36.8 Supine 2
102 Day 8 5.0 36.8 Supine 3
102 Day 15 6.0 37.0 Supine 1
102 Day 22 7.0 37.1 Supine 1
102 Day 29 8.0 36.9 Supine 1
102 Day 36 9.0 37.0 Supine 1
102 Day 43 / ET 10.0 37.0 Supine 2
102 Safety Follow-Up 12.0 36.9 Supine 1
I tried to achieve below highlighted with yellow and also, i want data like
in highlighted yellow color.
Subject FolderName FolderSeq VSTEMP VSTPT count Sub_cnt
101 Screening 1.0 37.1 Supine 1 1
101 Day 1 2.0 36.9 Supine 1 1
101 Day 8 5.0 36.8 Supine 1 1
101 Day 15 6.0 37.1 Supine 1 1
101 Day 22 7.0 36.7 Supine 1 1
101 Day 29 8.0 36.9 Supine 1 2
101 Day 36 9.0 36.9 Supine 2 2
101 Day 43 / ET 10.0 36.8 Supine 1 1
101 Safety Follow-Up 12.0 36.6 Supine 1 1
102 Screening 1.0 36.8 Supine 1 3
102 Day 1 2.0 36.8 Supine 2 3
102 Day 8 5.0 36.8 Supine 3 3
102 Day 15 6.0 37.0 Supine 1 1
102 Day 22 7.0 37.1 Supine 1 1
102 Day 29 8.0 36.9 Supine 1 1
102 Day 36 9.0 37.0 Supine 1 2
102 Day 43 / ET 10.0 37.0 Supine 2 2
102 Safety Follow-Up 12.0 36.9 Supine 1 1
Mastanvali
Calcite | Level 5
Data d;
infile datalines;
input Subject FolderName :$20. FolderSeq VSTEMP VSTPT:$10.;
dataline;
101 Screening 1.0 37.1 Supine
101 Day 1 2.0 36.9 Supine
101 Day 8 5.0 36.8 Supine
101 Day 15 6.0 37.1 Supine
101 Day 22 7.0 36.7 Supine
101 Day 29 8.0 36.9 Supine
101 Day 36 9.0 36.9 Supine
101 Day 43 / ET 10.0 36.8 Supine
101 Safety Follow-Up 12.0 36.6 Supine
102 Screening 1.0 36.8 Supine
102 Day 1 2.0 36.8 Supine
102 Day 8 5.0 36.8 Supine
102 Day 15 6.0 37.0 Supine
102 Day 22 7.0 37.1 Supine
102 Day 29 8.0 36.9 Supine
102 Day 36 9.0 37.0 Supine
102 Day 43 / ET 10.0 37.0 Supine
102 Safety Follow-Up 12.0 36.9 Supine
run;
 
I did the below logic:
proc sort data=d; by subject FolderSeq VSTEMP; run;

data d1;
set d;
 by subject folderseq VSTEMP;
retain count;
 if first.VSTEMP and first.subject  then count=1;
 if VSTEMP=lag(VSTEMP) and subject=lag(subject) then count=count+1;
 else count=1; 
run;
proc sort data=base2; by subject folderseq VSTEMP; run;
 
got the output like:
 
SubjectFolderNameFolderSeqVSTEMPVSTPTcount
101Screening1.037.1Supine1
101Day 12.036.9Supine1
101Day 85.036.8Supine1
101Day 156.037.1Supine1
101Day 227.036.7Supine1
101Day 298.036.9Supine1
101Day 369.036.9Supine2
101Day 43 / ET10.036.8Supine1
101Safety Follow-Up12.036.6Supine1
102Screening1.036.8Supine1
102Day 12.036.8Supine2
102Day 85.036.8Supine3
102Day 156.037.0Supine1
102Day 227.037.1Supine1
102Day 298.036.9Supine1
102Day 369.037.0Supine1
102Day 43 / ET10.037.0Supine2
102Safety Follow-Up12.036.9Supine1
While implementing the above logic only I tried to achieve the below sub_cnt and also, i want data like in sub_cnt column. 
SubjectFolderNameFolderSeqVSTEMPVSTPTcountSub_cnt
101Screening1.037.1Supine11
101Day 12.036.9Supine11
101Day 85.036.8Supine11
101Day 156.037.1Supine11
101Day 227.036.7Supine11
101Day 298.036.9Supine12
101Day 369.036.9Supine22
101Day 43 / ET10.036.8Supine11
101Safety Follow-Up12.036.6Supine11
102Screening1.036.8Supine13
102Day 12.036.8Supine23
102Day 85.036.8Supine33
102Day 156.037.0Supine11
102Day 227.037.1Supine11
102Day 298.036.9Supine11
102Day 369.037.0Supine12
102Day 43 / ET10.037.0Supine22
102Safety Follow-Up12.036.9Supine11
PaigeMiller
Diamond | Level 26

What is the logic here? Why is the value of sub_cnt equal to 2 for Day 29 subject 101?

--
Paige Miller
Mastanvali
Calcite | Level 5

we need to flag as yes for 3 or more consecutive values. but in my logic if i have 2 consecutive values also it is flagging yes but i do not want flag as yes if i have only 2 consecutives.

 

PaigeMiller
Diamond | Level 26

@Mastanvali wrote:

we need to flag as yes for 3 or more consecutive values. but in my logic if i have 2 consecutive values also it is flagging yes but i do not want flag as yes if i have only 2 consecutives.

 


I don't know what this means. 3 or more consecutive values of what? Flag for what reason? No flag is mentioned or shown in your original post.

 

How does the value of sub_cnt equal to 2 for Day 29 subject 101? Please walk me through this step-by-step.

--
Paige Miller

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
  • 6 replies
  • 656 views
  • 0 likes
  • 3 in conversation