<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Do Statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Split-records-using-DO-Statement/m-p/768201#M243638</link>
    <description>&lt;P&gt;I kept trying to do this in one DATA step, but I had to break it down into two separate ones. I know someone else would know how to do it in one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input usubjid 8. armcd :$30. arm :$300.;
infile datalines delimiter = " ";
datalines;
7959011 GPRTNKYKNSLWPCJEHGKG ACCUVE1\ACCUVE2\ACCUVE3\ACCUVE4\ACCUVE5\ACCUVE6\ACCUVE7\ACCUVE8\ACCUVE9\ACCUVE10
;
run;

data armcd (drop = i armcd max_len);
	set have (keep = usubjid armcd);
	max_len = max(length(armcd));
	do i = 1 to length(armcd) by 2 until (i &amp;gt; max_len);
		armcd_t = substr(armcd, i, 2);
		output;
	end;
run;

data arm (drop = i arm);
	set have (keep = usubjid arm);
	do i = 1 to countw(arm, "\");
		arm_t = scan(arm, i, "\");
		output;
	end;
run;

data want;
	merge
			armcd 	(in = a rename = (armcd_t = armcd))
			arm 	(in = b rename = (arm_t = arm));
	by		usubjid;
			if a and b;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs 	usubjid 	armcd 	arm
1 	7959011 	GP 	ACCUVE1
2 	7959011 	RT 	ACCUVE2
3 	7959011 	NK 	ACCUVE3
4 	7959011 	YK 	ACCUVE4
5 	7959011 	NS 	ACCUVE5
6 	7959011 	LW 	ACCUVE6
7 	7959011 	PC 	ACCUVE7
8 	7959011 	JE 	ACCUVE8
9 	7959011 	HG 	ACCUVE9
10 	7959011 	KG 	ACCUVE10&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Sep 2021 23:49:38 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2021-09-16T23:49:38Z</dc:date>
    <item>
      <title>Split records using DO Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-records-using-DO-Statement/m-p/768197#M243635</link>
      <description>&lt;P&gt;usubjid ARMCD ARM&lt;BR /&gt;7959011 GPRTNKYKNSLWPCJEHGKG ACCUVE1\ACCUVE2\ACCUVE3\ACCUVE4\ACCUVE5\ACCUVE6\ACCUVE7\ACCUVE8\ACCUVE9\ACCUVE10&lt;/P&gt;
&lt;P&gt;I want to split above single record into 10 records and each record should contains subjid, armcd and arm and each record should populate respected ARM and ARMCD accordingly.&lt;BR /&gt;By using the delimeter '\' successfully I have spatted ARM variable into 10 records but I am unable to split ARMCD accordingly with below program. Can anyone please help on this.&lt;BR /&gt;ARMCD has 20 characters and each 2 chars are belongs to 1 treatment.&lt;BR /&gt;GP = ACCUVE1&lt;BR /&gt;RT = ACCUVE2&lt;BR /&gt;NK = ACCUVE3.....&lt;/P&gt;
&lt;P&gt;In final dataset I need&lt;BR /&gt;usubjid ARMCD ARM&lt;BR /&gt;7959011 GP ACCUVE1&lt;BR /&gt;7959011 RT ACCUVE2&lt;BR /&gt;7959011 NK ACCUVE3................&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MY PROGRAM:&lt;BR /&gt;%let p = 0;&lt;/P&gt;
&lt;P&gt;data trtp_bi_test;&lt;BR /&gt;set t58;&lt;/P&gt;
&lt;P&gt;do i = 1 to 10;&lt;BR /&gt;length trtpval $200;&lt;BR /&gt;trtp = "TRT"||put(i,z2.)||"P";&lt;BR /&gt;trtplbl = "Planned Treatment for Period "||put(i,z2.);&lt;BR /&gt;trtpval = scan(armf,i,"\");&lt;/P&gt;
&lt;P&gt;j=0;&lt;BR /&gt;trtpcdval = substr(armcd, i+j, 2);&lt;BR /&gt;j+1;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 06:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-records-using-DO-Statement/m-p/768197#M243635</guid>
      <dc:creator>Santhosh01382</dc:creator>
      <dc:date>2021-09-21T06:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: Do Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-records-using-DO-Statement/m-p/768201#M243638</link>
      <description>&lt;P&gt;I kept trying to do this in one DATA step, but I had to break it down into two separate ones. I know someone else would know how to do it in one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input usubjid 8. armcd :$30. arm :$300.;
infile datalines delimiter = " ";
datalines;
7959011 GPRTNKYKNSLWPCJEHGKG ACCUVE1\ACCUVE2\ACCUVE3\ACCUVE4\ACCUVE5\ACCUVE6\ACCUVE7\ACCUVE8\ACCUVE9\ACCUVE10
;
run;

data armcd (drop = i armcd max_len);
	set have (keep = usubjid armcd);
	max_len = max(length(armcd));
	do i = 1 to length(armcd) by 2 until (i &amp;gt; max_len);
		armcd_t = substr(armcd, i, 2);
		output;
	end;
run;

data arm (drop = i arm);
	set have (keep = usubjid arm);
	do i = 1 to countw(arm, "\");
		arm_t = scan(arm, i, "\");
		output;
	end;
run;

data want;
	merge
			armcd 	(in = a rename = (armcd_t = armcd))
			arm 	(in = b rename = (arm_t = arm));
	by		usubjid;
			if a and b;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs 	usubjid 	armcd 	arm
1 	7959011 	GP 	ACCUVE1
2 	7959011 	RT 	ACCUVE2
3 	7959011 	NK 	ACCUVE3
4 	7959011 	YK 	ACCUVE4
5 	7959011 	NS 	ACCUVE5
6 	7959011 	LW 	ACCUVE6
7 	7959011 	PC 	ACCUVE7
8 	7959011 	JE 	ACCUVE8
9 	7959011 	HG 	ACCUVE9
10 	7959011 	KG 	ACCUVE10&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 23:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-records-using-DO-Statement/m-p/768201#M243638</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-09-16T23:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Do Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-records-using-DO-Statement/m-p/768205#M243641</link>
      <description>&lt;P&gt;Just use a little arithmetic to figure out where each ARMCD starts.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input usubjid armcd :$30. arm :$300.;
datalines;
7959011
GPRTNKYKNSLWPCJEHGKG
ACCUVE1\ACCUVE2\ACCUVE3\ACCUVE4\ACCUVE5\ACCUVE6\ACCUVE7\ACCUVE8\ACCUVE9\ACCUVE10
;

data want; 
  set have(rename=(armcd=armcd_string arm=arm_string));
  length ARMCD $2 ARM $20;
  do index=1 to 10 ;
    ARMCD=substr(armcd_string,2*(index-1)+1,2);
    ARM=scan(arm_string,index,'\');
    output;
  end;
  drop armcd_string arm_string;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    usubjid    ARMCD      ARM       index

  1    7959011     GP      ACCUVE1        1
  2    7959011     RT      ACCUVE2        2
  3    7959011     NK      ACCUVE3        3
  4    7959011     YK      ACCUVE4        4
  5    7959011     NS      ACCUVE5        5
  6    7959011     LW      ACCUVE6        6
  7    7959011     PC      ACCUVE7        7
  8    7959011     JE      ACCUVE8        8
  9    7959011     HG      ACCUVE9        9
 10    7959011     KG      ACCUVE10      10


&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Sep 2021 00:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-records-using-DO-Statement/m-p/768205#M243641</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-17T00:53:08Z</dc:date>
    </item>
  </channel>
</rss>

