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

Hi Team,

 

data x;
set y;
subj     recrd       dvact
101        1           action taken
101        2           withdraw from study
101        2           other
101        3           IRB given
101        4           Site reinstructed
101        5           subject counselled
101        5           other;
run;

 

i have raw data as above with same subject and different record numbers with different Dv actions taken .
So , i want to display that if a subject has same record numbers, then DV action should be displayed as 'MULTIPLE'(highlighted as bold letters in dataset)
as below output dataset SDTM.DV. Please look at the below output:

 

SDTM.DV dataset:
data DV;
set x;
subj          recrd           dvact
101           1                action taken
101           2                MULTIPLE
101           3                 IRB given
101           4                 Site reinstructed
101           5                MULTIPLE
;
run;

 

Multiple records in SDTM.Dv domain should be displayed in SUPP domain with their Dv actions as below output:

 

SDTM.SUPP_DV:

data SUPPDV;
set DV;
subj      recrd          QVAL                                     qlabel
101       2                withdraw from study          Multiple actions 2
101       2                other                                  Multiple actions 2
101       5                subject counselled            Multiple actions 3
101       5                other                                  Multiple actions 3
;
run;

 

Could you please provide code to generate DV and SUPPDV output;

 

Thanks in Advance

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

The best approach for this is a DATA step with a double DO loop. In both DO loops, read your dataset with

do until (last.recd);
  set have;
  by subj recd;

In the first loop, count the number of observations.

In the second loop, if the count is > 1, do the OUTPUTt only at LAST.RECD, setting dvact to MULTIPLE; otherwise, just OUTPUT.

 

For code, especially tested code, provide data in usable form, as shown here in one of your previous threads.

View solution in original post

5 REPLIES 5
andreas_lds
Jade | Level 19

Please change the title of you topic to something more meaningful and provide data in usable form.

japelin
Rhodochrosite | Level 12

When submitting, please prepare the data steps written in datalines so that we can easily process the data.

 

The following is an example of processing.

data have;
  infile datalines dsd;
  length subj recrd 8 dvact $20;
  input subj recrd dvact $;
datalines;
101,1,action taken
101,2,withdraw from study
101,2,other
101,3,IRB given
101,4,Site reinstructed
101,5,subject counselled
101,5,other
;
run;
proc sql;
  create table dv as
    select * , count(*) as cnt
      from have
      group by  subj, recrd
  ;
  update dv set dvact='MULTIPLE' where cnt>1;

  create table supp_dv as
    select * 
      from have
      group by  subj, recrd
      having count(*)>1
  ;
quit;
proc sort data=dv(drop=cnt) nodupkey;
  by subj recrd;
run;
data supp_dv;
  set supp_dv;
  length qlabel $40;
  rename dvact=qval;
  qlabel='Multiple actions X';/*what's 2 or 3 means you describe?*/
run;

The above is handled in sql mainly, but if you are not good at sql, you can count the number of records in the data step using the retain statement, first. variable.
Once you know the number of records, all you have to do is create two datasets.
Do a little research on your own.

 

mounikag
Obsidian | Level 7

Thanks will do that as suggested and the answered helped me. Thanks a lot

Kurt_Bremser
Super User

The best approach for this is a DATA step with a double DO loop. In both DO loops, read your dataset with

do until (last.recd);
  set have;
  by subj recd;

In the first loop, count the number of observations.

In the second loop, if the count is > 1, do the OUTPUTt only at LAST.RECD, setting dvact to MULTIPLE; otherwise, just OUTPUT.

 

For code, especially tested code, provide data in usable form, as shown here in one of your previous threads.

mounikag
Obsidian | Level 7

From next i will try to provide data in usable form . Thanks your answered help me .

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