<?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: Programming help required in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874107#M345321</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select id, count(distinct type) as n
from have
group by id
having n &amp;gt; 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will give you a dataset with the id values for which you want concatenating. In the follow-up step, you need to create a new id variable with sufficient length to accommodate the concatenated strings.&lt;/P&gt;</description>
    <pubDate>Fri, 05 May 2023 11:05:00 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-05-05T11:05:00Z</dc:date>
    <item>
      <title>Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873951#M345256</link>
      <description>I have two columns id,type&lt;BR /&gt;Each Id can have more than one type. Whenever Id has more than one type, type has to be concatenated with ID. When ID has only one type ,then type should not be concatenated with ID&lt;BR /&gt;Sample input data&lt;BR /&gt;ID Type&lt;BR /&gt;1 A&lt;BR /&gt;1 B&lt;BR /&gt;2 A&lt;BR /&gt;3 D&lt;BR /&gt;Output expected :&lt;BR /&gt;ID Type&lt;BR /&gt;1A A&lt;BR /&gt;1B B&lt;BR /&gt;2 A&lt;BR /&gt;3 D&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 04 May 2023 18:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873951#M345256</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-05-04T18:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873959#M345258</link>
      <description>&lt;P&gt;Seems like a homework assignment. Show us what you have tried.&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 18:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873959#M345258</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-04T18:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873968#M345260</link>
      <description>It is part of a huge requirement.I have simplified it for easier understanding.If you can provide the code for that ,it would be great.</description>
      <pubDate>Thu, 04 May 2023 18:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873968#M345260</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-05-04T18:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873971#M345261</link>
      <description>&lt;P&gt;Assumes the data is sorted by ID (which you didn't say, so is that a valid assumption?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    length id $ 8;
    set have;
    by id;
    if not (first.id and last.id) then id=cats(id,type);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 May 2023 18:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873971#M345261</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-04T18:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873972#M345262</link>
      <description>&lt;P&gt;You can use this method and then merge the results back with the original data for the duplicates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other option is a DoW loop but it will still do two passes of the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 18:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873972#M345262</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-04T18:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873974#M345263</link>
      <description>&lt;P&gt;It's hard to help you, without knowing what you're learning.&amp;nbsp; For example, have you learned about the BY statement?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seeing how you approach the problem will help people help you.&amp;nbsp; Are you thinking to do this with a DATA step? Or use PROC SQL? Or PROC FREQ?&amp;nbsp; Even if your code is not working, sharing it will help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you should post working SAS code to create the example input data.&amp;nbsp; Typically that is done with a DATA step with a CARDS statement.&amp;nbsp; That saves people time in having to write that code themselves.&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 18:40:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873974#M345263</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-04T18:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873986#M345268</link>
      <description>&lt;P&gt;Is ID numeric or character? If character, what is its defined length?&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 19:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873986#M345268</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-04T19:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874059#M345298</link>
      <description>&lt;P&gt;Hi, I have tried this..But it is not giving me desired output.Might be some complex programming is required for my requirement to be fulfilled.&lt;/P&gt;&lt;P&gt;Requirement is "If I have multiple Types for an ID ,then Type must be concatenated to ID field.&lt;/P&gt;&lt;P&gt;But, if we have only one type for an ID , then type need not be concatenated with ID field.Here,Jan has multiple types (Class1 and class2) .Hence, type must be concatenated with ID like Janclass1 ,Janclass2. But for feb and mar , concatenation need not happen since they have only one value for type ( class3 type for feb and&amp;nbsp; class4 type for mar).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expected output should have following ID values : janclass1 , janclass1,janclass2,feb,feb,mar&lt;/P&gt;&lt;P&gt;Please do not use Origin field in the logic to acheive this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input ID$ Type$ origin$;&lt;BR /&gt;datalines;&lt;BR /&gt;jan class1 UK&lt;BR /&gt;jan class1 UAE&lt;BR /&gt;jan class2 US&lt;BR /&gt;feb class3 INDIA&lt;BR /&gt;feb class3 MIDEAST&lt;BR /&gt;mar class4 NORWAY&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql;&lt;BR /&gt;create table temp as&lt;BR /&gt;Select ID,Type,count(*) as N from one&lt;BR /&gt;group by ID,Type;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;set temp;&lt;BR /&gt;if N=1 then ID=cats(ID,Type);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 04:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874059#M345298</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-05-05T04:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874060#M345299</link>
      <description>&lt;P&gt;Hi, I have tried this..But it is not giving me desired output.Might be some complex programming is required for my requirement to be fulfilled.&lt;/P&gt;&lt;P&gt;Requirement is "If I have multiple Types for an ID ,then Type must be concatenated to ID field.&lt;/P&gt;&lt;P&gt;But, if we have only one type for an ID , then type need not be concatenated with ID field.Here,Jan has multiple types (Class1 and class2) .Hence, type must be concatenated with ID like Janclass1 ,Janclass2. But for feb and mar , concatenation need not happen since they have only one value for type ( class3 type for feb and&amp;nbsp; class4 type for mar).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expected output should have following ID values : janclass1 , janclass1,janclass2,feb,feb,mar&lt;/P&gt;&lt;P&gt;Please do not use Origin field in the logic to acheive this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input ID$ Type$ origin$;&lt;BR /&gt;datalines;&lt;BR /&gt;jan class1 UK&lt;BR /&gt;jan class1 UAE&lt;BR /&gt;jan class2 US&lt;BR /&gt;feb class3 INDIA&lt;BR /&gt;feb class3 MIDEAST&lt;BR /&gt;mar class4 NORWAY&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql;&lt;BR /&gt;create table temp as&lt;BR /&gt;Select ID,Type,count(*) as N from one&lt;BR /&gt;group by ID,Type;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;set temp;&lt;BR /&gt;if N=1 then ID=cats(ID,Type);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 04:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874060#M345299</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-05-05T04:50:48Z</dc:date>
    </item>
    <item>
      <title>How to solve this/</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874066#M345325</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi, I have tried this. But&amp;nbsp;it is not giving me desired output. Might&amp;nbsp;be some complex programming is required for my requirement to be fulfilled. Requirement is "If I have multiple Types for an ID ,then Type must be concatenated to ID field. But, if we have only one type for an ID , then type need not be concatenated with ID field.Here,Jan has multiple types (Class1 and class2) .Hence, type must be concatenated with ID like Janclass1 ,Janclass2. But for feb and mar , concatenation need not happen since they have only one value for type ( class3 type for feb and&amp;nbsp; class4 type for mar). &amp;nbsp; The expected output should have following ID values : janclass1 , janclass1,janclass2,feb,feb,mar Please do not use Origin field in the logic to achieve&amp;nbsp;this.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data one;
input ID$ Type$ origin$;
datalines;
jan class1 UK
jan class1 UAE
jan class2 US
feb class3 INDIA
feb class3 MIDEAST
mar class4 NORWAY
;
run;

Proc sql;
create table temp as
Select ID,Type,count(*) as N from one 
group by ID,Type;
quit;

data two;
set temp;
if N=1 then ID=cats(ID,Type);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2023 06:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874066#M345325</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-05-05T06:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this/</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874073#M345326</link>
      <description>&lt;P&gt;Please do not post identical questions.&lt;/P&gt;
&lt;P&gt;And how is this different than your question in &lt;A href="https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873986#M345268" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/873986#M345268&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 06:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874073#M345326</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-05T06:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this/</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874080#M345327</link>
      <description>&lt;P&gt;Search Google for "double DoW-loop".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input ID$ Type$ origin$;
datalines;
jan class1 UK
jan class1 UAE
jan class2 US
feb class3 INDIA
feb class3 MIDEAST
mar class4 NORWAY
;
run;

data want;
  length newID $ 16;
  do _N_ = 1 by 1 until(last.id);
    set one;
    by id notsorted;

    if first.id then n_type=0;
    if Type NE lag(Type) then n_type+1;
  end;

  do _N_ = 1 to _N_;
    set one;
    if n_type &amp;gt; 1 then newID = cats(ID,Type);
                  else newID = ID;
    output;
  end;

  drop ID n_type;
  rename newID = ID;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 07:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874080#M345327</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-05T07:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874081#M345313</link>
      <description>&lt;P&gt;Look here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-solve-this/m-p/874066/highlight/false#M42860" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-solve-this/m-p/874066/highlight/false#M42860&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 07:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874081#M345313</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-05T07:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this/</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874090#M345328</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442456"&gt;@Sathya3&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to request you provide meaningful (but brief) descriptions of the actual problem you are trying to solve as the title/subject of your post. Subject lines like "how to solve this" and "programming help required" are not helpful and don't describe the actual problem and could apply to virtually every post here in the SAS forums. We're trying to help you, please go ahead from now on and help us by creating meaningful description of the problem in the subject line&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 09:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874090#M345328</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-05T09:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Programming help required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874107#M345321</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select id, count(distinct type) as n
from have
group by id
having n &amp;gt; 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will give you a dataset with the id values for which you want concatenating. In the follow-up step, you need to create a new id variable with sufficient length to accommodate the concatenated strings.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 11:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874107#M345321</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-05T11:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this/</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874112#M345330</link>
      <description>&lt;P&gt;I combined the posts.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 11:36:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874112#M345330</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-05T11:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this/</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874128#M345339</link>
      <description>&lt;P&gt;Thanks for sharing your code, and sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You code is very close to working.&amp;nbsp; I only see two problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the SQL step, you are using count(*) grouped by ID and Type.&amp;nbsp; This will tell you that there are two records for jan class1 and one record for jan class2.&amp;nbsp; But it doesn't tell you that there are two different values of TYPE for jan.&amp;nbsp; For that, you can use count(&lt;STRONG&gt;distinct&lt;/STRONG&gt;(type)) grouped by ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the data step, you need to increase the length of ID, or the value will be truncated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this code will give what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input ID$ Type$ origin$;
datalines;
jan class1 UK
jan class1 UAE
jan class2 US
feb class3 INDIA
feb class3 MIDEAST
mar class4 NORWAY
;
run;

Proc sql;
  create table temp as
  Select *,count (distinct(Type)) as N from one 
  group by ID;
quit;

data two;
  length ID $12 ;
  set temp;
  if N&amp;gt;1 then ID=cats(ID,Type);
run;

proc print data=two ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2023 13:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Programming-help-required/m-p/874128#M345339</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-05T13:21:11Z</dc:date>
    </item>
  </channel>
</rss>

