BookmarkSubscribeRSS Feed
vraj1
Quartz | Level 8

i have a datastep which i am using to calculate withdrawals but i need to set condition by using another dataset which has multiple reasons for withdrawals. Can i do that in same datastep? any help.

data attached:

datastep used is : the one which is bold should be overwritten with the other dataset(_adds) which is attached. How can i take this new dataset by using any condition in the below dataset

 

data work.Disp_Withdraw_w2;
	set work.Disp_Withdraw_w1;
	length desc $50. dsreas_fmt $50. sort1 sort2 8.;

	if compress(actarm) = "BLINDED" then
		do;
			desc = vlabel(SAFFL);
			dsreas_num_BLINDED = 1;
			dsreas_fmt = "Number of Patients";
			sort1 = 1;
			sort2 = 0;
			output;

			if SAFFL='Y' then
				do;
					if EOTSTT = 'Completed' then
						do;
							dsreas_num_BLINDED = 1;
							dsreas_fmt = " Completed";
							sort2 = 1;
							output;
						end;
					else if EOTSTT ='Discontinued' then
						do;
							dsreas_num_BLINDED = 1;
							dsreas_fmt = " Withdrawn";
							sort2 = 2;
							output;
						end;
				end;

			if PDCTREAS ne "" then
				do;
					desc= "ByPrim";
					dsreas_num_BLINDED = 1;
					dsreas_fmt = " "||PDCTREAS;
					sort1 = 88;
					output;
				end;
		end;

	if compress(actarm) = "PENDING" then
		do;
			desc = vlabel(SAFFL);
			dsreas_num_PENDING = 1;
			dsreas_fmt = "Number of Patients";
			sort1 = 1;
			sort2 = 0;
			output;

			if SAFFL='Y' then
				do;
					if EOTSTT = 'Completed' then
						do;
							dsreas_num_PENDING = 1;
							dsreas_fmt = " Completed";
							sort2 = 1;
							output;
						end;
					else if EOTSTT ='Discontinued' then
						do;
							dsreas_num_PENDING = 1;
							dsreas_fmt = " Withdrawn";
							sort2 = 2;
							output;
						end;
				end;

			if PDCTREAS ne "" then
				do;
					desc= "ByPrim";
					dsreas_num_PENDING = 1;
					dsreas_fmt = " "||PDCTREAS;
					sort1 = 88;
					output;
				end;
		end;
run;

 

14 REPLIES 14
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I believe this has been mentioned on all your other posts:

PleAsE pOST tEst data IN tHE Form oF a dAtAstep iN the body of YoUR post, usINg the {i} code WinDOW.

Note the above is done deliberately to show how hard it is to read code which has no formatting issues, has no casing consistency etc.

data work.disp_withdraw_w2;
  set work.disp_withdraw_w1;
  length desc $50. dsreas_fmt $50. sort1 sort2 8.;
  if compress(actarm)="BLINDED" then do;
    desc = vlabel(saffl);
    dsreas_num_blinded=1;
    dsreas_fmt="Number of Patients";
    sort1=1;
    sort2=0;
    output;
    if saffl='Y' then do;
      if eotstt='Completed' then do;
        dsreas_num_blinded=1;
        dsreas_fmt=" Completed";
        sort2=1;
        output;
      end;
      ...
    end;
    ...
  end;
run;

Now to your issue, without seeing the data its hard to say, does the data match in any way, i.e. can you merge the two together based on some condition, if so then do that, and in your if just use the variable merged on from the second dataset, then drop all variables from the second dataset.  If you can't merge the two, how does the look up work?  You may have to use some sort of code generation from the rules dataset to generate the other.

vraj1
Quartz | Level 8

Sorry for that. I had indented the code but while pasting it got back to normal. extremely sorry for that.

attaching the 2 datasets. i tried to merge but in one dataset there is one record per observation and the other has multiple as it contains multiple reasons for withdrawal. i tried to transpose the second one which has multiple records and merge by subjid but then it creates multiple observations.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I would say that merging is probably best here.  Got a meeting so this is only quick, but setup the one with dups as:

data adds_inter (keep=subjid list);
  set adds;
  length list $2000;
  retain list;
  by subjid;
  if first.subjid then list="";
  list=catx(',',list,avalc);
  if last.subjid then output;
run;

This should give you one row per subject which you can then merge onto the other dataset and use in your if.

vraj1
Quartz | Level 8

Thanks, but i need to have summary i.e number of withdrawals reasons.

I am making a table with one option as primary reason for withdrawal and another option with all reasons

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Is that a summary including each of the reasons from the other dataset?  Not sure how its meant to look, if its just a count of the number in the other dataset:

data adds_inter (keep=subjid cnt);
  set adds;
  retain cnt;
  by subjid;
  cnt=ifn(first.subjid,0cnt+1);
  if last.subjid then output;
run;

Basically the idea is to get your data as you need it for the output, so manipulate it into a 1 row structure.

vraj1
Quartz | Level 8

Basically i need is an option which keeps either primar reason or all reasons which was there in other dataset.

 

Attached is the sample output for primary reason which i get now but i need to keep an option for all reasons from the other dataset.

and in other dataset it only has reasons for withdrawal.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yep, standard withdrawal table.  In which case I have seen two approaches:

1) In ADSL programming have a primary reason variable.

2) Define in the dataset where reasons are kept, which consititutes "primary" and merge that on.  Alternatively if they are all to be there, summarise that dataset, then append to your other dataset.  I.e. don't do it all in one step. 

 

 

vraj1
Quartz | Level 8

Thanks a lot, I transposed the other dataset and merged it.

i did the below after transpose. when i use the below code it gives error as &i resolves to numeric value

NOTE: Invalid numeric data, SECREAS1='Withdrawal of consent' , at line 1 column 2.

is there anyother way to do this.

 

         %if %upcase(&RptReas.) = ALL %then %do;

               	desc = "All";
				dsreas_num_%scan(&ArmList.,&k., #)=%scan(&ReasLst., &i.);
				if dsreas_num_%scan(&ArmList.,&k., #) then do;
					dsreas_fmt = "    "||&i.;
					sort2 = &i.;
					output;
				end;
			%end;

it got resolved to 

data work.Disp_Withdraw_w21;
   set work.Disp_Withdraw_w2;
   if compress(actarm) = "BLINDED" then do;
        desc = "All";
        dsreas_num_BLINDED = SECREAS1;
   if dsreas_num_BLINDED then do;
        dsreas_fmt = "    "||2;
        sort2 = 2;
        output;
    end;
    end;
    if compress(actarm) = "PENDING" then do;
        desc = "All";
        dsreas_num_PENDING = SECREAS1;
    if dsreas_num_PENDING then do;
        dsreas_fmt = "    "||2;
        sort2 = 2;
        output;
     end;
     end;
run;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Macro vars are always text, so you can just do:

dsreas_fmt = "    "||&i.;

To

dsreas_fmt = "    &i.";

 

vraj1
Quartz | Level 8

i changed it but still it somehow resoles to numeric

dsreas_num_%scan(&ArmList.,&k., #)=%scan(&ReasLst., &i.);

 i have attached my test data earlier post.

 

NOTE: Invalid numeric data, SECREAS1='Withdrawal of consent' , at line 1 column 2.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

/Sorry, the code you post:

dsreas_num_%scan(&ArmList.,&k., #)=%scan(&ReasLst., &i.);

Does not match anything else you posted before.  What is armlist, reaslist &i etc.  Look at what I have posted.  Get your data into a usable way, do datasteps to get it as you want then merge the data together, forget macros and other things this is basic data manipulations.   

Kurt_Bremser
Super User

As you probably have been told several times by now, use either the "little running man" or {i} icons to post SAS code, logs or text data that must not be reformatted by the forum software. Posting code in the main window is NOT recommended.

 

vraj1
Quartz | Level 8
data work.Disp_Withdraw_w2;
        set work.Disp_Withdraw_w1;
        length desc $50. dsreas_fmt $50. sort1 sort2 8.;
     if compress(actarm) = "BLINDED" then do;
        	desc = vlabel(SAFFL);
        	dsreas_num_BLINDED = 1;
        	dsreas_fmt = "Number of Patients";
        	sort1 = 1;
        	sort2 = 0;
        	output;
        if SAFFL='Y' then do;
        	if EOTSTT = 'Completed' then do;
        	dsreas_num_BLINDED = 1;
        	dsreas_fmt = "   Completed";
        	sort2 = 1;
        	output;
        end;
        else if EOTSTT ='Discontinued' then do;
        	dsreas_num_BLINDED = 1;
        	dsreas_fmt = "   Withdrawn";
        	sort2 = 2;
        	output;
        end;
        end;
        if PDCTREAS ne "" then do;
        	desc= "ByPrim";
        	dsreas_num_BLINDED = 1;
        	dsreas_fmt = "    "||PDCTREAS;
        	sort1 = 88;
     	   output;
        end;
     end;
     if compress(actarm) = "PENDING" then do;
        	desc = vlabel(SAFFL);
        	dsreas_num_PENDING = 1;
        	dsreas_fmt = "Number of Patients";
        	sort1 = 1;
        	sort2 = 0;
        	output;
        if SAFFL='Y' then do;
        	if EOTSTT = 'Completed' then do;
        	dsreas_num_PENDING = 1;
        	dsreas_fmt = "   Completed";
       		sort2 = 1;
        	output;
        end;
        else if EOTSTT ='Discontinued' then do;
       		dsreas_num_PENDING = 1;
        	dsreas_fmt = "   Withdrawn";
        	sort2 = 2;
        	output;
        end;
        end;
        if PDCTREAS ne "" then do;
        	desc= "ByPrim";
        	dsreas_num_PENDING = 1;
        	dsreas_fmt = "    "||PDCTREAS;
        	sort1 = 88;
        	output;
        end;
     end;
run;

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