<?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: Put &amp;quot;-&amp;quot; between 2 variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329101#M73573</link>
    <description>&lt;BR /&gt;data have;&lt;BR /&gt;   input id   $ number $;&lt;BR /&gt;   datalines;&lt;BR /&gt;3 25&lt;BR /&gt;3 12&lt;BR /&gt;3 10&lt;BR /&gt;4 15&lt;BR /&gt;;quit;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;length fst_val $20;&lt;BR /&gt; &lt;BR /&gt;retain fst_val;&lt;BR /&gt; &lt;BR /&gt;if first.id then fst_val=number;&lt;BR /&gt;Else number=catx('-',fst_val,number);&lt;BR /&gt;&lt;BR /&gt;If last.id then output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Can you check the code, what is missing. Not working</description>
    <pubDate>Wed, 01 Feb 2017 14:34:15 GMT</pubDate>
    <dc:creator>user24</dc:creator>
    <dc:date>2017-02-01T14:34:15Z</dc:date>
    <item>
      <title>Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329068#M73566</link>
      <description>&lt;P&gt;How can i put '-' between these 2 variable for same id&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id &amp;nbsp; &amp;nbsp; number &amp;nbsp; &amp;nbsp; code&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; 25 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a&lt;/P&gt;
&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;new table i need&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id &amp;nbsp; &amp;nbsp;number &amp;nbsp; code&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp;25-12-10 &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;
&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 13:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329068#M73566</guid>
      <dc:creator>user24</dc:creator>
      <dc:date>2017-02-01T13:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329077#M73567</link>
      <description>&lt;P&gt;Please post test data in the form of a datastep, its very simple just follow this post.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I don't understand why you are so reluctant to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for your problem, I am not typing that in so this is general (and assumes number is character):&lt;/P&gt;
&lt;P&gt;1) sort the data so first.id and last.id are the range&lt;/P&gt;
&lt;P&gt;2) do something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  length fst_val $20;
  retain fst_val;
  if first.id then fst_val=number;
  if last.id and not(first.id) then do;
    number=catx('-'.fst_val,number);
  end;
  else if first.id and last.id then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Feb 2017 13:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329077#M73567</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-01T13:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329078#M73568</link>
      <description>&lt;P&gt;what if there were more than 2 instances of the same ID? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 13:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329078#M73568</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-02-01T13:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329085#M73569</link>
      <description>&lt;P&gt;yes, thats'a good question. Thank you. I modified my question&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 13:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329085#M73569</guid>
      <dc:creator>user24</dc:creator>
      <dc:date>2017-02-01T13:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329089#M73570</link>
      <description>&lt;P&gt;The amount of observations per group doesn't affect the solution.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;solution will still work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Slight changes are required to condition.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt; set have;&lt;BR /&gt; length fst_val $20;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;retain fst_val;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if first.id then fst_val=number;&lt;BR /&gt;Else&amp;nbsp;number=catx('-'.fst_val,number);&lt;BR /&gt;&lt;BR /&gt;If last.id then output;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 13:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329089#M73570</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-01T13:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329101#M73573</link>
      <description>&lt;BR /&gt;data have;&lt;BR /&gt;   input id   $ number $;&lt;BR /&gt;   datalines;&lt;BR /&gt;3 25&lt;BR /&gt;3 12&lt;BR /&gt;3 10&lt;BR /&gt;4 15&lt;BR /&gt;;quit;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;length fst_val $20;&lt;BR /&gt; &lt;BR /&gt;retain fst_val;&lt;BR /&gt; &lt;BR /&gt;if first.id then fst_val=number;&lt;BR /&gt;Else number=catx('-',fst_val,number);&lt;BR /&gt;&lt;BR /&gt;If last.id then output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Can you check the code, what is missing. Not working</description>
      <pubDate>Wed, 01 Feb 2017 14:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329101#M73573</guid>
      <dc:creator>user24</dc:creator>
      <dc:date>2017-02-01T14:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329102#M73574</link>
      <description>&lt;P&gt;I think a little more tweaking might be needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt; set have;&lt;BR /&gt; length fst_val $20;&lt;/P&gt;
&lt;P&gt;retain fst_val;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if first.id then fst_val=number;&lt;BR /&gt;else&amp;nbsp;&lt;FONT color="#ff0000"&gt;fst_val&lt;/FONT&gt;=catx('-'.fst_val,number);&lt;BR /&gt;&lt;BR /&gt;If last.id then output;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;drop number;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;rename fst_val=number;&lt;/FONT&gt;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 14:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329102#M73574</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-01T14:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329105#M73575</link>
      <description>&lt;P&gt;Thank you for the test data, here is working code:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id $ number $;
datalines;
3 25
3 12
3 10
4 15
;
run;

proc sort data=have;
  by id number;
run;

data want;
  set have;
  by id;
  length fst_val $20;
  retain fst_val;
  if first.id then fst_val=number;
  if last.id and not(first.id) then do;
    number=catx('-',fst_val,number);
    output;
  end;
  else if first.id and last.id then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Feb 2017 14:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329105#M73575</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-01T14:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329106#M73576</link>
      <description>it takes only 2 variable.</description>
      <pubDate>Wed, 01 Feb 2017 14:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329106#M73576</guid>
      <dc:creator>user24</dc:creator>
      <dc:date>2017-02-01T14:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329108#M73577</link>
      <description>&lt;P&gt;Sorry, are you asking to have all values within the list, as your original post seemed to indicate &amp;lt;min&amp;gt;-&amp;lt;max&amp;gt;.&lt;/P&gt;
&lt;P&gt;If so then:&lt;/P&gt;
&lt;PRE&gt;data have;&lt;BR /&gt; input id $ number $;&lt;BR /&gt;datalines;&lt;BR /&gt;3 25&lt;BR /&gt;3 12&lt;BR /&gt;3 10&lt;BR /&gt;4 15&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc sort data=have;&lt;BR /&gt; by id number;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want (drop=fst_val);&lt;BR /&gt; set have (rename=(number=fst_val));&lt;BR /&gt; by id;&lt;BR /&gt; length number $20;&lt;BR /&gt; retain number;&lt;BR /&gt; if first.id then number=fst_val;&lt;BR /&gt; else number=catx("-",number,fst_val);&lt;BR /&gt; if last.id then output;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;Do however note that the final string has to be long enough to store all the numbers in this instance. &amp;nbsp;For example your test data creates number as char(8), default when length not specified. &amp;nbsp;8 Characters is just about enough to hold 3 * 2 + 2 characters, but any more and you will have problems. &amp;nbsp;That is why in the program above I rename the incoming $8 variable and put the result in a new string which is $200 to hold a lot more possibilities. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 14:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329108#M73577</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-01T14:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329113#M73578</link>
      <description>&lt;P&gt;to a similar problem,I po0sted the brief data step which can be seen at&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Combine-multiple-observations-into-one-if-they-have-the-same-Id/m-p/329016#M62531" target="_self"&gt;https://communities.sas.com/t5/SAS-Procedures/Combine-multiple-observations-into-one-if-they-have-the-same-Id/m-p/329016#M62531&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 15:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329113#M73578</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-02-01T15:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Put "-" between 2 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329136#M73587</link>
      <description>might be better to just see the code adapted for this case&lt;BR /&gt;data out1 ( compress= yes  keep= code collection ) ;&lt;BR /&gt;   length collection $10000 ; &lt;BR /&gt;   Do item=1 by 1 until( last.code ) ;&lt;BR /&gt;      set your_data ;&lt;BR /&gt;      by code ;&lt;BR /&gt;      collection = catX( '-', collection, number ) ;&lt;BR /&gt;   End ;   &lt;BR /&gt;run ;</description>
      <pubDate>Wed, 01 Feb 2017 16:05:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-quot-quot-between-2-variable/m-p/329136#M73587</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-02-01T16:05:36Z</dc:date>
    </item>
  </channel>
</rss>

