<?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 How to solve this? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874061#M345300</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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 May 2023 05:00:02 GMT</pubDate>
    <dc:creator>Sathya3</dc:creator>
    <dc:date>2023-05-05T05:00:02Z</dc:date>
    <item>
      <title>How to solve this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874061#M345300</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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 05:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874061#M345300</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-05-05T05:00:02Z</dc:date>
    </item>
    <item>
      <title>How to solve this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874063#M345305</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;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 05:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874063#M345305</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-05-05T05:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874068#M345306</link>
      <description>&lt;P&gt;A little modification to your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
create table temp as
Select *,count(distinct Type) as N from one 
group by ID;
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:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874068#M345306</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-05-05T06:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874070#M345307</link>
      <description>&lt;P&gt;if I type N^=1 , jan is not appended with class2 and feb is appended with class3.This is not desired ouput.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the desired output of ID column&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;janclass1&lt;BR /&gt;janclass1&lt;BR /&gt;janclass2&lt;BR /&gt;feb&amp;nbsp;&lt;BR /&gt;feb&amp;nbsp;&lt;BR /&gt;mar&amp;nbsp;&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:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874070#M345307</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-05-05T06:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874151#M345349</link>
      <description>&lt;DIV&gt;This code works only for this given dataset, based on your real data and expectations it could be developed further, like creating macrovar containing multiple values and using it in data step with IN operator etc..&amp;nbsp;&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=one;
by id type;
run; 

data _null_;
	set one;
	by id type;
	if not last.id and last.type then call symputx('value', strip(id));
run;
%put &amp;amp;=value;

data want;
	length id $15;
	set one(rename=(id=_id));
	if strip(_id) eq "&amp;amp;value" then id= cats(_id, type);
	else id = _id;
	drop _id;
proc print;run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 05 May 2023 14:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874151#M345349</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-05-05T14:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874171#M345355</link>
      <description>&lt;P&gt;Please show the complete code of a data step or procedure call. Better is to capture the result from the LOG and share the log. Copy the text from the log of the code an all related messages. Then on the forum open a text box and paste the text. The text box preserves formatting of text and will help with the diagnostic characters SAS sometimes displays with problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442456"&gt;@Sathya3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;if I type N^=1 , jan is not appended with class2 and feb is appended with class3.This is not desired ouput.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why should typing N^=1 do anything? You show an incomplete statement, no operations done, you don't even show an IF . Your example data does not include any variable named N. So the value of the just created variable N will be missing and likely shows a message in the log:&lt;/P&gt;
&lt;PRE&gt;NOTE: Variable N is uninitialized.
&lt;/PRE&gt;
&lt;P&gt;which tells you there is no value assigned to N.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you mean the SAS automatic variable _N_ that counts iterations of the data step and in simple code indicates the row number of an observation in a data set???&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 16:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874171#M345355</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-05T16:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874172#M345356</link>
      <description>&lt;P&gt;Thus code may need an additional mechanism for extending the length of id.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 16:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874172#M345356</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-05T16:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874225#M345379</link>
      <description>Absolutely right!</description>
      <pubDate>Sat, 06 May 2023 01:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874225#M345379</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-05-06T01:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874226#M345380</link>
      <description>I also update your sql code, please check it. And as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; reminded, you need to expand the length of ID.</description>
      <pubDate>Sat, 06 May 2023 01:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874226#M345380</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-05-06T01:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874235#M345382</link>
      <description>&lt;P&gt;Seems like a silly thing to do.&amp;nbsp; Just use ID and TYPE as the key variables.&amp;nbsp; No need to mess either one of them up by adding other things to them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is simple SQL query that will do what you asked for.&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
;

proc sql;
create table want as
select case when count(distinct type)=1 then id
            else cats(id,type)
       end as ID
     , *
from one
group by ID
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    ID            Type     origin

 1     feb          class3    MIDEAST
 2     feb          class3    INDIA
 3     janclass2    class2    US
 4     janclass1    class1    UK
 5     janclass1    class1    UAE
 6     mar          class4    NORWAY

&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 May 2023 03:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-solve-this/m-p/874235#M345382</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-06T03:47:53Z</dc:date>
    </item>
  </channel>
</rss>

