<?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 Creating multiple records from single record in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574033#M12631</link>
    <description>&lt;P&gt;Hi I have dataset as follows:&lt;/P&gt;&lt;P&gt;obs&amp;nbsp; col1&lt;/P&gt;&lt;P&gt;&amp;nbsp;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; ar/t; br/t&lt;/P&gt;&lt;P&gt;&amp;nbsp;2.&amp;nbsp; &amp;nbsp; &amp;nbsp; k&lt;/P&gt;&lt;P&gt;&amp;nbsp;3.&amp;nbsp; &amp;nbsp; &amp;nbsp; m-p, i&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create another dataset as follows:&lt;/P&gt;&lt;P&gt;obs&amp;nbsp; col1&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; b&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; k&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp;m&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp;n&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; o&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; p&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp;i&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you help me with that. Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jul 2019 22:18:08 GMT</pubDate>
    <dc:creator>kothasaikrishna</dc:creator>
    <dc:date>2019-07-16T22:18:08Z</dc:date>
    <item>
      <title>Creating multiple records from single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574033#M12631</link>
      <description>&lt;P&gt;Hi I have dataset as follows:&lt;/P&gt;&lt;P&gt;obs&amp;nbsp; col1&lt;/P&gt;&lt;P&gt;&amp;nbsp;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; ar/t; br/t&lt;/P&gt;&lt;P&gt;&amp;nbsp;2.&amp;nbsp; &amp;nbsp; &amp;nbsp; k&lt;/P&gt;&lt;P&gt;&amp;nbsp;3.&amp;nbsp; &amp;nbsp; &amp;nbsp; m-p, i&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create another dataset as follows:&lt;/P&gt;&lt;P&gt;obs&amp;nbsp; col1&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; b&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; k&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp;m&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp;n&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; o&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; p&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp;i&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you help me with that. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 22:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574033#M12631</guid>
      <dc:creator>kothasaikrishna</dc:creator>
      <dc:date>2019-07-16T22:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple records from single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574034#M12632</link>
      <description>Are those all the rules? How do you know which to expand and which to truncate?</description>
      <pubDate>Tue, 16 Jul 2019 22:31:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574034#M12632</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-16T22:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple records from single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574035#M12633</link>
      <description>I have series alphabets from m to p which were mentioned as m-p, I need to expand those and put them in multiple rows</description>
      <pubDate>Tue, 16 Jul 2019 22:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574035#M12633</guid>
      <dc:creator>kothasaikrishna</dc:creator>
      <dc:date>2019-07-16T22:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple records from single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574036#M12634</link>
      <description>So we can ignore the first two observations and everything from them? Only worry about that last record then with the hyphen? It's always a hyphen and no other fields have hyphens? If we don't understand the rules, we can't code a solution.</description>
      <pubDate>Tue, 16 Jul 2019 22:40:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574036#M12634</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-16T22:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple records from single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574040#M12635</link>
      <description>I have the instructions that i need to take out r/t in the first observation and put the two alphabets a, b in two different observations, for the third observation i need to expand from m to p and put them in different observations and alphabet i comes as the last observation. Thanks!</description>
      <pubDate>Tue, 16 Jul 2019 22:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574040#M12635</guid>
      <dc:creator>kothasaikrishna</dc:creator>
      <dc:date>2019-07-16T22:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple records from single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574044#M12636</link>
      <description>&lt;P&gt;This is a start, don't know your exact rules.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	length colout1 $1 _coltemp $ 11;
	set have;
	do _i = 1 to countw(col1,":,"); *loop all the words;
		_coltemp = strip(scan(col1,_i,":,")); 
		*Three different cases, a list, a span or a single value.;
		if index(_coltemp,"-")&amp;gt;0 then do;
			*Span, Might be problematic if the casing is different from start to end. ;
			_start = scan(_coltemp,1,"-");
			_end = scan(_coltemp,2,"-");
			*Rank gets the ASCII value for us to loop from start to end.;
			do _j = rank(_start) to rank(_end);
				*Use byte function to go from ASCII to string. ;
				colout1 = byte(_j);
				output;
			end;
		end;
		else if index(_coltemp,":")&amp;gt;0 then do;
			*A list of values separated (in this case with : ). ;
			do _j =1 to countw(_coltemp,":");
				*Loop all of the values. ;
				colout1 = scan(_coltemp,_j);
				output;
			end;
		end;
		else do;
			*Single value version;
			colout1 = _coltemp;
			output;
		end;
	end;
	drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jul 2019 23:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574044#M12636</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-07-16T23:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple records from single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574051#M12638</link>
      <description>&lt;P&gt;Not sure why this isn't working for the last i, but need to be done. Perhaps someone else can fix it, it's pretty close.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	original="ar/t; br/t";
	output;
	original="k";
	output;
	original="m-p, i";
	output;
run;

data want;
	set have;
	*number of terms;
	n_terms=countc(original, ";,")+1;
    p1=compress(original, 'r/t');

	do i=1 to n_terms;
		term=scan(p1, i, ';, ');

		if find(term, '-') then
			do;
				start_letter=rank(scan(term, 1, '-'));
				end_letter=rank(scan(term, 2, '-'));

				do i=start_letter to end_letter;
					term=byte(i);
					output;
				end;
			end;
	     else output;

	end;
	keep term original;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jul 2019 01:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574051#M12638</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-17T01:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple records from single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574062#M12640</link>
      <description>&lt;P&gt;You are reusing the counter variable (i) in your inner loop. So, it will be more than two the second time it tries to do the outer loop. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I would use&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;p1=tranwrd(original, 'r/t','');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;instead of the compress. Compress removes all chars, not just that exact string. So, if you have "t-u", then the code will remove "t" as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 02:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574062#M12640</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-07-17T02:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple records from single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574064#M12641</link>
      <description>&lt;P&gt;Thanks, it was dinner time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	original="ar/t; br/t";
	output;
	original="k";
	output;
	original="m-p, i";
	output;
run;

data want;
	set have;
	*number of terms;
	n_terms=countc(original, ";,")+1;
	
	*remove r/t;
    p1=tranwrd(original, 'r/t', '');


	do i=1 to n_terms;
	    *separate into items;
		term=scan(p1, i, ';, ');

        *check if fields contains hyphen;
		if find(term, '-') then
			do;
			    *find start and end of loop by converting to ascii and back;
				start_letter=rank(scan(term, 1, '-'));
				end_letter=rank(scan(term, 2, '-'));

                *loop through and output for each letter;
				do j=start_letter to end_letter;
					term=byte(j);
					output;
				end;
			end;
	     *if no hyphen output;
	     else output;

	end;
	keep term original n_terms;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jul 2019 02:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574064#M12641</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-17T02:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple records from single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574293#M12674</link>
      <description>&lt;P&gt;Thank you so much! that works.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 17:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-multiple-records-from-single-record/m-p/574293#M12674</guid>
      <dc:creator>kothasaikrishna</dc:creator>
      <dc:date>2019-07-17T17:08:56Z</dc:date>
    </item>
  </channel>
</rss>

